Corda postgres table setup during the deployNodes - corda

I'm trying to build nodes which needs to be deployed in Multiple VM's.
When I run the deployNodes, the corresponding tables are getting created.
Is there anyway that after copying the nodejs to VM and execute commands to generate the tables on the Postgres in the corresponding VM machines.

First, you need to create one schema per node inside your database. For instance, here you can find the steps for PostgreSQL database.
Then, set initializeSchema to true inside the node.conf of your node; with this option enabled, the node will automatically create all its tables when it starts for the first time.

DeployNodes is a Gradle plugin which will help you to set up the node configurations. Database tables are created only when you run the node.
You connect to the default in-memory H2 database or you connect to Postgres, the logic to generate the tables in the database is the same. By default, all the required tables are generated automatically by the node in the database.

Related

Flyway init new db

I have existing database postgres which not using Flyway and i need replicate it.
How to move existing database state to new empty database?
I don't have any migration sql.
So I am expecting command like generateChangelog in Liquibase but it seems in Flyway not existing command like that.
Flyway currently only manages the scripts that you create. It doesn't create scripts for you. So, in order to take an existing database and get it into Flyway processing, you'll need to generate the scripts for that database. You can use the methods outlined here to get the scripts for your database. Then, just rename them to the Flyway standard. You'll be off and running.

Store Flyway metadata table externally

So just exploring the possibility of using flyway to maintain my DDL statements against Amazon Athena using Athena provided JDBC driver, Athena supports only CREATE statements (hive DDL) and no INSERTS.
So if database metadata table is the only one that flyway creates and updates, Is there anyway I can externalize the creating, storing into a totally different database ?
Currently this is not possible in flyway, as the schema history is read from/written to the database defined by the current jdbc connection. You can see this for yourself in the JDBCTableSchemaHistory file.
If you wish to add this support, you could create a pull request on the repo, or just add an issue detailing exactly what you want the behaviour to be.

Symfony2 doctrine2 migration script into table instead of file

I am working with doctrine:migrations:diff in order to prepare database evolutions.
This command creates files into app/DoctrineMigrations
Thoses files contains sql commands in order to upgrade or downgrade database scructure.
I want to store those sql commands into the database itself. In fact, i have several instances of databases. If sql commands are store into files, it is a big problem.
I have read somewhere that DoctrineMigrations bundle can create a table called "migration_versions", but i do not manage to find where i have read this...
I cannot really understand what you're trying to do.
Migrations are used when your code needs altered database structure. For example, a new table or a new column. These new requirements for a table or column comes from your newly written code, so it's only natural to place the migrations also as a code in your repository.
How and when would migrations even get to your database? How would you guarantee that migration is executed before the code changes, which use that new structure?
Generally, migrations are used in this way:
You develop your code, add new features, change existing ones. Your code needs changes to database.
You generate doctrine migration class, which contains needed SQL statements for your current database to get to the needed state.
You alter the class adding any more required SQL statements. For example, UPDATE statements to migrate your data, not only the structure.
You execute migration locally.
You test your code with database changes. If you need more changes, you either add new migration, or execute migration down, delete it and regenerate it. Never change the migration class, as you'll loose what's supposed to be in the database and what's not.
You commit your migration together with code that uses it.
Then comes the deployment part:
- For each server, upload the code, clear and warm-up cache, run other installation scripts. Then run migrations. And only then switch to the new code.
This way your database is always in-sync with current code in the server that uses that database.
migration_versions database table is created automatically by doctrine migrations. It holds only the version numbers of migration classes - it's used for keeping track which migrations were already run and which was not.
This way when you run doctrine:migrations:migrate all not-yet-ran migrations are executed. This allows to migrate few commits at once, have several migrations in a commit etc.

flyway: db init without maven?

IMHO using maven for migrations is fine only for development machines.
On servers you don't usually have maven available (and it might be impossible to have it installed there).
So: How do I init a database without maven?
Do I just call flyway.init()?
What if the db is already init-ed?
Can I execute sql statements to init the db?
My foreign keys and indexes are different/messed up in between different databases instances, so I already made a complete schema script and tested it with data export, schema drop, schema re-create and data restore. I am going to do that on all databases to ensure that they are exactly the same.
Yes, you can simply call flyway.init()
You can use flyway.status() to check if the DB has been inited.
This process will become easier with Flyway 1.8, where a new property called initOnMigrate has been introduced. The first time it runs, it will then init an existing non-empty database (PROD) when you run migrate or just migrate on an empty one (DEV).

Is there anyway to "add" tables to existing database when using Code First?

I want to add a module build on Code First to a running website, which already has an database. If I set my module to run on separated database, it works fine.
But my friend want to just "add" tables created by my modules to existing database, without adding a new database.
Is there anyway to archive that?
The solution is simple and very easy:
Run the module to create a new, clean database
Use SQL Server to generate sql scripts that create tables of that database. I personally think the metadata table is not needed
Run those scripts against target database
Modify the connection string to point to target database
Now it runs flawless! I'm so happy
Thank you.

Resources