GithubHelp home page GithubHelp logo

Comments (8)

webman avatar webman commented on April 27, 2024 1

After more experience with Sequelize and another ORMs I understand a lot of things in development and deploying projects.
This is not issue, it is absolutely normal - defining structure in model and create few migrations for updating database structure through time.

I think current issue may be closed.

from express-example.

kjloveless avatar kjloveless commented on April 27, 2024

@webman I may be a little off with the answer, but here it goes.

The model is used to represent the table as an object.

A migration is used to transition the database state, so if you add or remove something from your model you can run a migration and it will update the database. You can also undo migrations to return to a previous state, so say you needed to undo the change you made you could undo that migration and return to the previous instance of your database state.

Does this make sense or help?

from express-example.

webman avatar webman commented on April 27, 2024

@kjloveless In other frameworks (such as Express, Adonis, Laravel) we not need to define structure twice. Usually done only migration (DB schema), but in model file dont specify structure. And this is comfortable for development - structure defined in one file.

from express-example.

kjloveless avatar kjloveless commented on April 27, 2024

@webman I'm not sure I follow exactly what you're trying to get at honestly... You can think of the model as the object that you are going to get back from your database and the migration is simply a log of changes applied to your database. So you're really defining the structure of a table with the migration and of an object with the model... Does that make sense?

[https://laracasts.com/discuss/channels/laravel/the-difference-between-a-model-and-a-migration](Maybe this link will help?)

I do think it would be nice however if the migration files would be able to be generated based off the corresponding model file, but people has made additional libraries to solve this as well already. This would probably get rid of your feeling of defining things twice..

In summary, they're two separate thing...

@sushantdhiman can you confirm my answer? or clear things up for Webman if I misspoke?

from express-example.

ryanburnette avatar ryanburnette commented on April 27, 2024

I advocate this example repository being explicit in showing migration structure, but perhaps it could also give an example of how to skip the migrations and use sync.

from express-example.

ryanburnette avatar ryanburnette commented on April 27, 2024

Another thing to consider is that generating a model with --attributes allows you to define the structure once, generating the model and migration. Edits would then require defining the same information twice though.

from express-example.

DRoet avatar DRoet commented on April 27, 2024

Tracking issue for this is basically here: sequelize/sequelize#5213

from express-example.

papb avatar papb commented on April 27, 2024

Hi everyone, thanks for raising this issue, sorry to take so long to give you more attention. I believe this is a common question, I will try to improve the docs on this at some time, but a short answer is as follows.

Models are the main thing. The feature of migrations exist for version-controlling the state of your database; migrations are not mandatory. One can start to use migrations long after the database is already running, even in production. The duplicated structure that could be seen in the old example was caused by the decision of applying migrations since the very beginning, representing the state change from 'database does not even exist' to 'now database exists with these tables'. In my opinion, this is not very useful. What I would recommend is to just set up the database without migrations, and start using migrations only after your service is already running in production and you have to change something.

Feel free to ask me any further questions 😁

from express-example.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.