• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Migration Class Names

#1
I'm having an issue with CI 3 migrations and I'm wondering if anyone else has run into this and how they fixed it.

If I have the following migration file:

Code:
20121031100537_alter_blog.php

Then I have the following migration class:

PHP Code:
Migration_Alter_blog 

If I need to alter the blog table again, however:

Code:
20131031100537_alter_blog.php

It has the same class name:

PHP Code:
Migration_Alter_blog 

And because of the way CI load and initializes migrations, it'll throw a PHP error for redeclaring a class. Is there a way around this that anyone has found? If not, what's the best practice for handling these naming conflicts?

I've been able to get around it by adding the timestamp to the class name:

PHP Code:
Migration_Alter_blog_20131031100537 

But that requires a filename of:

Code:
20131031100537_alter_blog_20131031100537.php

Which just feels messy.

Any help or input is appreciated.
Reply

#2
According to the documentation you either use an incremental index or timestamp.

From what you have shown is that your trying to use the same file without incrementing
the value in the file name.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#3
I just give more details. So, names like alter_blog_add_category, or alter_blog_remove_tags.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#4
(08-04-2017, 04:47 AM)InsiteFX Wrote: According to the documentation you either use an incremental index or timestamp.

From what you have shown is that your trying to use the same file without incrementing
the value in the file name.

No, I'm going from 2012... to 2013... in the example above, so I'm incrementing the timestamp as the documentation says, but the timestamp is just for the file name, not the class name.

(08-04-2017, 08:39 AM)kilishan Wrote: I just give more details. So, names like alter_blog_add_category, or alter_blog_remove_tags.

That's a good call. Simple.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.