How web2py performs migrations:

Web2py takes your db.define_table statement, and stores a pickle of
its structure. These files are saved in
databases/<connectionstringhash>.<tablename>.table Web2py takes this
structure that is saved on the filesystem and loads it up when you
perform db.define_table. If your db.define_table is different than the
pickled file, web2py will perform a migration on the database,
executing the necessary SQL. Web2py assumes the database is in the
format of the .table files. Therefore if your .table files ever come
out of sync of your database (such as can happen in a multi-developer
environment), web2py will attempt to perform migrations that are
invalid. (hence the need for fake_migrate)

So to start here are some definitions

Keyword arguments:
migrate -- Specifies if web2py should perform migrations on the
underlying database. This includes the creation/deletion of tables,
creation/addition/alteration/removal of columns. Web2py compares the
.table pickle with the define_table statements to figure out the
migration scheme. (Default True)
fake_migrate -- Regenerates .table files to look exactly like your
db.define_table statement, regardless of the state of the database.
Migrations WILL NOT be performed if this is True (default False).

So this is what happens when you specify the following options

migrate = True, fake_migrate = False

Web2py will migrate the database if your define_table statement
differs from the pickle file.

migrate = False, fake_migrate = False

Web2py will not migrate the database, it assumes that your
db.define_table statement looks exactly like the database. If you do
alter anything without migrations, and the SQL is incorrect it will
through a OperationalError.
This is the recommended setting for production, since there is no
overhead of web2py needing to read the pickle files from the
filesystem. (pickle files are locked when written to)

migrate = True, fake_migrate = True
migrate = False, fake_migrate = True

Web2py will regenerate your .table files. Migrations will not be
performed since it is "faking" a migrate on the pickle files, and not
the database. This is also useful if you would like to see the SQL
that will be generated from a migrate via sql.log before actually
performing the migration.

-Thadeus





On Fri, Feb 26, 2010 at 3:35 PM, villas <villa...@gmail.com> wrote:
> There are quite a few postings about this but I have never exactly
> understood how this is supposed to work.  My expectation is that
> fake_migrate should work alongside migrate like this:
>
> 1. If migrate = True,  fake_migrate = True:   DB  and .table files are
> both modified/migrated.
>
> 2. If migrate = True,  fake_migrate = False:  DB  modified but .table
> files are not.
>
> 3. If migrate = False,  fake_migrate = True:  DB not modified but
> the .table files are (to correspond with the model).
>
> 4. If migrate = False,  fake_migrate = False:  Nothing is modified.
>
> Notes
> a. You always get an exception if Web2py cannot get the DB to
> correspond with the .table files.  In that case you have to fiddle
> around and get the two singing off the same sheet.
>
> b. There is no way of creating a model or a .table file from an
> existing DB.  If you search hard you'll find some hacked code that
> gives a head start,  but really it's something you have to do by hand.
>
> Now,  having written the above,  I have two questions:
>
> 1. Are my expectations correct?  (e.g. I think I'm wrong about 1?).
>
> 2. Why doesn't 3 seem to work?   I cannot get fake_migrate to create
> a .table file.  If it does not, could we please have a function that
> does so?
>
> Regards,
> -- David
>
> --
> You received this message because you are subscribed to the Google Groups 
> "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to 
> web2py+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/web2py?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to