Is it planned for the future that `prisma migrate`...
# prisma-migrate
m
Is it planned for the future that
prisma migrate
(new migrate) can handle renaming of models & fields?
t
Yes, if it turns out to be something people want, we may build and interactive prompt for your migrations, where you can specify renamings, some simple data migrations, etc. at generation time.
๐Ÿ‘ 2
For now, it is less convenient but completely supported: you can edit the migration with an
ALTER TABLE x RENAME TO y;
step to replace the
DROP
and
CREATE
that are generated by migrate.
๐Ÿ‘ 3
d
To add to @tomโ€™s comments, this is also one of the main reasons why the new version of Prisma Migrate uses SQL for migrations โ€“ it gives you the flexibility to control how migrations are carried out. The process for renaming with the new version of Migrate would look as follows: 1. Rename a field in your Prisma schema 2. Generate an SQL migration with Prisma Migrate 3. Update the SQL to rename the column rather than delete and create a new column (as in Tomโ€™s example).
๐Ÿ‘ 2
m
Thanks @tom and @Daniel Norman, this is indeed what I do and it works great. For autoincrement fields I also need to adjust the name of the sequence. But with SQL I'm way more flexible with such adjustments, really good! ๐Ÿ™‚
๐ŸŽ‰ 3
t
Just for curiosity: we are starting with SQL because it's less work for us and we can ship it faster, but it would also be possible to have a migration DSL (in typescript) that migrations could be written in. Would it be much better for you, or would you still prefer the current workflow of having an editable SQLย file generated for you? SQL will always be an option for the SQL databases we support, even in that case.
๐Ÿ‘€ 1
f
SQL is a good first step. A DSL would be a natural next step. Sometimes you need to do data migrations that cannot be expressed in pure SQL. I've used typeorm migrations and I think they work great.
๐Ÿ‘ 1
d
@Fredrik Would you mind sharing examples of data migrations that were hard to express in pure SQL?
f
E.g. we used https://www.npmjs.com/package/short-uuid to generate unique IDs for new records.
Easily done in TS, not so in SQL.
๐Ÿ‘ 1