Closed
Description
I think it is a reasonable expectation that it would be possible to:
- rename a column
- change the data type
- add or drop the null constraint
- change the default
And probably other things that I have not thought of.
I would imagine the syntax for doing this would be something like
knex.Schema.table('table_name', function (t) {
t.string('my_column').renameTo('something_else');
t.string('my_column').changeTo('text');
t.string('my_column').nullable() < adds nullable if not already present
t.string('my_column').notNullable() < removes nullable if present
t.string('my_column').defaultTo('whatever') < adds or updates the default
});
Maybe there needs to be something extra in the chain, possibly at the knex.Schema.table
level to indicate that this is a modify statement not an add.
I realise that this is tricky to implement across various databases, especially in SQLite where you have to create a whole new table, but in a system which requires migrations, without these tools it is going to be necessary to use knex.raw and write all the migrations for each DB supported, which sort of defeats the point of having a nice ORM especially one which is about to support migrations.