Welcome Guest, Not a member yet? Register   Sign In
How migrations work?
#1

[eluser]spescina[/eluser]
Hi guys.

I've read about migrations on the user guide and around on the net. I'm about to start using it but there are some things I cannot understand.

Let's look at a simple scenario.

I've 5 migrations files in my migrations folder (000..004)
- 000_install (10 tables and some rows)
- 001_create_auth_section (2 tables)
- 002_insert_upload_privilege (1 row)
- 003_create_article_section (3 tables)
- 004_insert_download_privilege (1 row)

I've enabled the migrations config file and I have the current migration set on 2.
I've the migration controller with 3 methods: current(), to_version($version) and latest()

In this situation my db should be with 12 tables and with the upload_privilege row.
Now I want to reach migration 4

CI gives me 3 way in order to achieve this
1) migration->version(4)
2) migration->latest()
3) set the current config to 4 and run migration->current()

first question:
when using these methods
a) only migration files 003/004 are going to be processed or
b) all migrations files up the requested version are executed each time?

second question:
if the answer to the previous question is a), using the third method shouldn't be discouraged?

third question:
when going back to a previous version, does CI know how to rollback starting from current version config value?

I think this system is rather "dark".
I think I need an enlightment...
#2

[eluser]PhilTem[/eluser]
First answer:
CI_Migration creates a table in your database holding the version of the database tables. If you increase the migration version (I usually do it in the config/migrations.php file) then CI_Migration will look, what version the database is and what version you have provided. Given these two values it will only perform the migrations in between (i.e. greater than the database stored version value until (and including) the value in the config file)

Second answer:
Guess that one's not necessary to give since CI_Migration works differently than you thought (I guess)

Third answer:
If going back, CI_Migration will call the down-method() of all migrations that you have thus dropping tables or removing rows.

Hope that shed some light into your darkness.

If you're still experiencing dark areas, just go ahead and read the CI_Migration source code Wink
#3

[eluser]spescina[/eluser]
Ok.
Now that I know that a database table is created by the system everything is clear. I missed it in the user guide page.
Sorry.

Thanks man.
#4

[eluser]PhilTem[/eluser]
It's mentioned as the second paragraph in the user's guide Wink

Quote:The database table migration tracks which migrations have already been run so all you have to do is update your application files and call $this->migrate->current() to work out which migrations should be run. The current version is found in config/migration.php.




Theme © iAndrew 2016 - Forum software by © MyBB