MyBatis Generator from ddl script instead of database connection - mybatis

Is there any way to use myBatis generator based on a ddl script instead of a real database?

You can't do this out of the box as mybatis generator relies on jdbc to do introspection of the database metadata. But it is rather easy to do it.
The easiest way is to use some in-memory database (H2 may work for you) to do the following:
execute ddl script against the in-memory db
run mybatis generator via java API specifying in-memory db

Related

Run SQL script on multiple schemas with Flyway

I am migrating the DB using Flyway. I have a SQL script file which need to run on multiple schemas hosted on a single database.
In my SQL file if I mention ${db_schema} as the parameter and supply with different schema names, will that work? Is there any other approaches to handle this scenario?
SET search_path TO ${db_schema};
You should be able to use placeholders in flyway to handle more than one schema. Here's an article that outlines how that works.

PrismaJS Reverse Engineered from DB (like Hibernate)?

I have a lot of experience using Hibernate to reverse engineer entity classes (Java) from the DB instance, (this process is the 'reverse' of evolving the DB based on writing entity classes). Often, with existing data and processes, it is essential to treat the DB as the single 'source of truth' and create entities based on the DB.
I'm interested in using Prisma (TS/JS), and I've been looking for generators which can generate Prisma schema (which is used to generate entity classes) based on an existing DB (reverse engineering).
Is there a way to reverse engineer the Prisma schema from an existing DB? Are there any known projects to add this functionality?
I believe you're looking for Prisma's introspection feature. According to the Introspection Concept Article in the Prisma docs:
You can introspect your database using the Prisma CLI in order to generate the data model in your Prisma schema.
....
Introspection is often used to generate an initial version of the data model when adding Prisma to an existing project.
The prisma cli command for introspection once you have the database connection set up:
npx prisma introspect
This should update your Prisma Schema file with the existing database tables.

JPA standard property: how will a JPA provider create schema without knowing database system password?

JPA has a standard property
javax.persistence.schema-generation.create-database-schemas
that asks JPA provider to create a database(schema for oracle db) for schema-generation.
Creating database requires system password, but there is no such JPA property for db system password. How it works?
JPA uses some database connection, and that one has username/password.
If you want JPA to create the schema it is assumed that the user for the connection has sufficient privileges.
If you do not like this for a production environment you can generate the SQL statements upfront (you'd have to tell the system which DB/dialect to use at generation time) and then have a DB admin execute that script prior to application deployment.

Cannot use copy function with jdbc driver [duplicate]

I have a project with Spring, Hibernate and PostgreSQL and have to use ANT to create schema with data:
<sql driver="org.postgresql.Driver"
classpath="src/main/webapp/WEB-INF/lib/postgresql-9.1-901.jdbc4.jar"
url="jdbc:postgresql://localhost:5433/postgres"
userid="postgres"
password="pw123"
autocommit="true"
src="src/main/sql/dbbackup.sql">
</sql>
but I get this error:
C:\Users\<user>\<workspace>\<Project>\antdb.xml:22: org.postgresql.util.PSQLException: ERROR: COPY from stdin failed: The JDBC driver currently does not support COPY operations.
Don't know if somehow we could use postgresql.copy class here?
PgJDBC doesn't support COPY directly, but it does via the CopyManager API you can get from the PGConnection interface of the java.sql.Connection returned by PgJDBC.
Unfortunately, you can't use that from a plain SQL file where you mix COPY operations in with other commands.
Personally, I'd shell out to psql to run .sql files using the Ant <exec> task. That way you can include COPY data in-line in your SQL files.
It'd be nice to enable PgJDBC to handle COPY, but it's not easy. It's effectively a different protocol mode in PostgreSQL, and it doesn't make much sense to use the usual JDBC interfaces with prepared statements, execute, etc, for it. We could provide an execSQLScript on the custom PGconnection but that wouldn't help you out much because things like Ant's <sql> task wouldn't use it. You'd have to write a custom task.
Instead, PgJDBC would have to pretty much lie to clients - when it entered COPY mode after a COPY command, it'd have to ignore the JDBC spec and not really do what it was supposed to in response to JDBC statement executes. This would be likely to break all sorts of things.
So - for now, by far the easiest option is to just exec the psql command to do what you want.

Start firebird backup from sql

In Sybase sqlAnywhere you could do:
BACKUP DATABASE DIRECTORY 'directory'
to trigger a backup.
Is there a similar solution in Firebird?
It would be easier with a sql-command, than having to distribute gbak.exe.
There is no SQL statement to perform a backup, you either need to use gbak.exe, or your application (or a companion application) needs to use the Firebird service API to perform the backup.
For example Jaybird (the Java/JDBC driver for Firebird) and the Firebird ADO.net provider implement this functionality, but it might be simpler just to include gbak.exe and call it from within your application with the right command line options.