Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorsuthern
    • CommentTimeDec 6th 2007 edited
     
    I'm creating an inventory system, thus the name is 'Inventory' in the following examples.

    This install script worked great: ./script/migrate Inventory install

    But now I want to modify a row in one of the tables (table name = parts). I'm going to do a removeColumn followed by a addColumn (I was using choosen_vendor, but that did not automatically relate it to the id in the vendor table, so now I'm going to switch to a column name of vendor_id, in hopes that it will build the relation automatically.)

    So basically I know that my new installer/migrate php file needs to contain this:
    =================================================================
    function up_2(){
    $this->removeColumn('parts','choosen_vendor'); // remove choosen vendor
    $this->addColumn('parts','vendor_id'); // ID for the choosen vendor

    function down_2(){
    $this->removeColumn('parts','vendor_id'); // remove choosen vendor id
    $this->addColumn('parts','choosen_vendor'); // add the generic data field back
    }
    ================================================================
    But where do I put that? If I put it before or after the 'up_1' and 'down_1' functions inside inventory_installer.php, and then run './script/migrate Inventory install', the console returns 'Can't go up to version 1, you're already on version 1'.

    I get this same error even if I comment out the 'up_1' and 'down_1' functions.
    I tried './script/migrate Inventory install 2', and it said 'upgrading', but when I did './script/migrate Inventory install' again, the error still said I was at version 1 still.. hmm.

    I'd be happy to write up a tutorial on this and post it if someone helps me out here. ;-)

    Thanks ahead of time!
    -Suthern
    • CommentAuthorIneX
    • CommentTimeDec 6th 2007
     
    It should work if you add it like this to your "inventory_installer.php" (btw.: there was a closing bracket } missing at "function up_2()..."):

    function up_1() {
    /* your initial code */
    }

    function down_1() {
    /* your initial code */
    }

    function up_2(){
    $this->removeColumn('parts','choosen_vendor'); // remove choosen vendor
    $this->addColumn('parts','vendor_id'); // ID for the choosen vendor
    }

    function down_2(){
    $this->removeColumn('parts','vendor_id'); // remove choosen vendor id
    $this->addColumn('parts','choosen_vendor'); // add the generic data field back
    }
    • CommentAuthorsuthern
    • CommentTimeDec 6th 2007 edited
     
    Ahh, I can't believe I missed something that simple. Thanks, it works great!

    I've added a short tutorial in the "how to" section of the wiki. Feel free to edit/add/remove stuff to make it clearer.

    -Suthern
    • CommentAuthorIneX
    • CommentTimeDec 6th 2007
     
    I just looked at your tutorial, which is very nice written I think.
    But there's one thing: I may be wrong (not soooo much into Akelos), but shouldn't you do all installer-manipulations concerning your books table in the "book_installer"?

    You just go back to the main installer, booklink_installer, if you want to add further tables or something which concerns your whole project in general.
    • CommentAuthorsuthern
    • CommentTimeDec 6th 2007
     
    I was just going to do a post about that very thing. Why do we have both 'book_installer' and 'booklink_installer'?

    It seems that there could be some confusion done the road as to which revision in which installer.. Just imagine if someone went into book_installer, added a few columns (or somehow changed it), did 'Book install'. Now, if I were to do 'Booklink uninstall 1', then 'Booklink install 2', the changes inside the 'book_install' would no longer apply.

    How do other '... on Rails' frameworks handle this?
    -Suthern
    • CommentAuthorIneX
    • CommentTimeDec 7th 2007 edited
     

    Now, if I were to do 'Booklink uninstall 1', then 'Booklink install 2', the changes inside the 'book_install' would no longer apply.

    Let's look at it like this:

    You have set up your new Application. You first go into "booklink_installer" to define the database-tables you need for your project (you define "books", "authors",...). Now you migrate using "./script/migrate Booklink install". This gives you the following files (next to "booklink_installer.php"):

    • book_installer.php
    • author_installer.php

    Versions:

    • booklink_installer @ Version 1 (Main Database setup)
    • book_installer @ Version 0
    • author_installer @ Version 0

    Now you do all changes concerning the books table in your "book_installer.php"; starting with Version "up_1()", and so on. Same goes for author.

    When you do a downgrade on the books-table, you do it like "./script/migrate Book uninstall 1".

    This will drop all settings you did AFTER you installed the main application (booklink), and will not concern anything else except your books-table settings.

    Summary: Versions can be different in each installer (booklink, book, author, ...). Just make sure, you install (using "./script/migrate Book install") only those to which you've added new version-functions, rather than updating you whole application ("booklink") every time.

    Update: oh baby, this was an "installer" too much,... baby (as from Austin Powers ;-))

Add your comments
    Username Password
  • Format comments as