Improve Database Manager with existing schema changes synchronization

Naturally. It was more about being able to clone it in the new db manager and then have it ready to track changes, avoiding the need to jump into another tool etc.

But seeing the instructions George wrote, that’s good enough for me for a while.

So what you mean is to import an existing schema into the db manager of your dev target, then let wappler handle the migration files as normally and when you chose to deploy to another target Wappler would handle the initial schema import plus all the successive migration files?

Well I don’t want to hijack someone else’s thread here :grin:

My two experiences/thoughts would be:

  1. If you’ve created the db schema outside of Wappler, but want to create a new target, it would be good to be able to clone the existing schema as is, to the new target using the db manager.
  2. If you’ve already created the db schema inside Wappler, there might have been some things have happened to some of your changes or you’ve deleted some or you’ve made some changes outside Wappler that aren’t registered as changes. In this instance you could again, clone the as is schema and apply to a new target in Wappler using the db manager.

That’s my take on it.

1 Like

Good points! I made a feature request for better tracking

Copying and pasting from the other topic.

When you say clone in 1 you mean to create an initial migration file right?
Wappler would read the schema of the db and create an initial knex migration file as a starting point.

In 2 it would be an import/export losing all migration files. Again it would read the schema and create an initial migration file of the current state of schema. Then you could apply that migration file in another target.

All in all, both scenarios could be handled by translating existing schemas into an initial migration file. Ultimately the end is to have a starting point that can be reproducible in another target and compatible with knex migrations.

I believe knex doesn’t have a tool for this like sequelize(but sequelize is an ORM). Although some ideas could be used extracted from this project.

An alternative could be to create an initial migration file and seed? Something in these terms?

exports.seed = function(knex, Promise) {
    var sql = fs.readFileSync('.dump.sql').toString();
    return knex.raw('DROP DATABASE test')
       .then(() => knex.raw('CREATE DATABASE test'))
       .then(() => knex.raw(sql))