Using migrations without versioning?

Published 6 months ago by heykatieben

This might be a silly question (full disclosure: I'm a Laranewbie :).

Anyway: I'd like to use migrations without versioning. I love the versioning for a live project, though when first developing a project it seems nicer to me to be able to see/edit everything on a database in one file. Is there a way to do this that I'm missing, to be able to edit migrations / apply them without blowing away data?

My current solution is to export data, refresh migrations, import data. Is there a better way?

ejdelmonico

All you have to do is modify any migration file and migrate:refresh. That gets rid of all the migrations due to change while developing. Great for changing column names, etc. However, you really should have a separate migration for each model.

Dry7
Dry7
6 months ago (152,030 XP)

@heykatieben If you already have data in the database, it is better to create a new migration for each change.

heykatieben

Oops, I meant that I have one migration file per model. Wouldn't migrate:refresh blow away my current data?

Dry7
Dry7
6 months ago (152,030 XP)

@heykatieben this command will delete all data

Cronix
Cronix
6 months ago (786,650 XP)

@heykatieben Yes it would destroy the data.

Each change to the db should be done in it's own migration. If you want to add a column to a table, make a new migration. If you want to change a columns data type, make a new migration. No data loss (unless you do it purposefully, like remove a column from a table that has data, or drop the entire table, etc).

If you want to keep editing your migrations as you go using the method you are (one migration file per table), you will just have to deal with losing data when you want to run the migrations. Not sure why you'd want to do that. It's much better to do it incrementally, which is how migrations were intended to be used.

Yes it's nice to have everything for a table in a single file. No, it's not practical. Can you do it? Yes, but you'll lose data each time since it deletes the tables first and then recreates them.

mikail10000000

You have to use seeder to have all the data that you need for development , for example if you need a user to be in the db than create a user seeder and each time when you migrate:refresh --seed see the last parameter --seed it will populate the database with the dummy data , if you have to preserve all of the data that you input while testing than you should create new migration files and alter the tables and than just do migrate command the downside is that there might be too many migration files so I only start creating "alter" migration files when the project in production and the data must be preserved

Please sign in or create an account to participate in this conversation.