cli icon indicating copy to clipboard operation
cli copied to clipboard

Generate initial migration from model?

Open jsumners opened this issue 9 years ago • 203 comments

I'm just getting started with Sequelize and the CLI. I want my project's initial database to be bootstrapable with sequelize db:migrate (i.e. create the database from nothing with an initial set of migrations). In that regard, it seems to me that I am duplicating a lot of code.

  1. I create my initial model, wherein I fully describe the table
  2. I then create a migration for it where I mostly just copy and paste the previously written definition
  3. If there are changes to be made before committing, I get to make them in multiple places

I have a simple two table test project at https://github.com/jsumners/sequelize-migration-test that shows what I'm describing.

Would it not be possible (make more sense) for sequelize migration:generate to read the already defined model and generate the migration from that definition?

jsumners avatar Jul 21 '15 21:07 jsumners

Yes. That would be a good idea and I'm planning to do that since a while already but never found the time for that :(

On Tue, Jul 21, 2015 at 11:09 PM, James Sumners [email protected] wrote:

I'm just getting started with Sequelize and the CLI. I want my project's initial database to be bootstrapable with sequelize db:migrate (i.e. create the database from nothing with an initial set of migrations). In that regard, it seems to me that I am duplicating a lot of code.

  1. I create my initial model, wherein I fully describe the table
  2. I then create a migration for it where I mostly just copy and paste the previously written definition
  3. If there are changes to be made before committing, I get to make them in multiple places I have a simple two table test project at https://github.com/jsumners/sequelize-migration-test that shows what I'm describing.

Would it not be possible (make more sense) for sequelize migration:generate to read the already defined model and generate the migration from that definition?

Reply to this email directly or view it on GitHub: https://github.com/sequelize/cli/issues/157

sdepold avatar Jul 21 '15 21:07 sdepold

If I get a chance I'll see if I can work something up. But I'm not sure I'll have the opportunity.

jsumners avatar Jul 22 '15 12:07 jsumners

+1 :)

o5 avatar Oct 19 '15 14:10 o5

+1

mwain avatar Oct 27 '15 16:10 mwain

+1. Well, it is just javascript, so im going to make a file that exports the javascript object, that the model in models/ and migrations/ can import. Not going to set my self up for the inevitable 'change one place, but forgot the other'

DenLilleMand avatar Nov 04 '15 13:11 DenLilleMand

+1

bbbeeeee avatar Dec 07 '15 19:12 bbbeeeee

+1

agolendukhin avatar Apr 07 '16 17:04 agolendukhin

Is there any progress? or alternative?

amit034 avatar Jun 02 '16 14:06 amit034

no progress afaik

sdepold avatar Jun 03 '16 05:06 sdepold

+1 Will be the very popular feature. I hope this feature will be implemented

zmts avatar Jun 30 '16 19:06 zmts

+1

kkleidal avatar Jul 26 '16 14:07 kkleidal

+1

suricactus avatar Aug 16 '16 20:08 suricactus

+1

oliv23 avatar Oct 15 '16 13:10 oliv23

+1

WaqqasMeraj avatar Oct 20 '16 05:10 WaqqasMeraj

+1

juniorplenty avatar Oct 20 '16 19:10 juniorplenty

+1

atlantageek avatar Nov 04 '16 13:11 atlantageek

+1

bradleyy1012 avatar Nov 28 '16 01:11 bradleyy1012

+1

jcfinnerup avatar Nov 29 '16 11:11 jcfinnerup

+1

Anomnimel avatar Dec 26 '16 12:12 Anomnimel

+1

darrenchiu avatar Jan 12 '17 09:01 darrenchiu

By the way, now I use https://github.com/Vincit/objection.js/ Very nice convenient ORM

zmts avatar Jan 12 '17 16:01 zmts

+1

Though currently I'm doing it this way: https://gist.github.com/notgiorgi/7276aae5baebb5725799ce0f5b8468f3

notgiorgi avatar Jan 24 '17 14:01 notgiorgi

I would like to start working on this feature. Can anyone give me pointers on where I should begin? Thanks a lot.

SargeKhan avatar Jan 25 '17 11:01 SargeKhan

+1

omeragich avatar Feb 05 '17 15:02 omeragich

+1

iDVB avatar Feb 16 '17 16:02 iDVB

+1

willsr avatar Mar 06 '17 06:03 willsr

+1

roybrey avatar Mar 29 '17 19:03 roybrey

+1

minhnhat2807 avatar Apr 17 '17 02:04 minhnhat2807

+1

laynef avatar Apr 19 '17 17:04 laynef

+1

cuxs avatar Apr 21 '17 12:04 cuxs