py::qodb::upgrade Namespace Reference


Functions

def upgrade_to_2
def upgrade_to_1
def upgrade_to_0
def add_field
def reset_models
def resave_model
def run


Function Documentation

def py::qodb::upgrade::add_field (   model,
  fields 
)

        Manually add a field to current table

Almost all taken from django/core/management.py
00052                                 :
00053         """
00054                 Manually add a field to current table
00055 
00056         Almost all taken from django/core/management.py
00057         """
00058         opts = model._meta
00059         cursor = connection.cursor()
00060         for f in [f for f in opts.fields if f.name in fields] :
00061                 col_type = f.db_type()
00062                 tablespace = f.db_tablespace or opts.db_tablespace
00063                 if col_type is None:
00064                         # Skip ManyToManyFields, because they're not represented as
00065                         # database columns in this table.
00066                         continue
00067                 # Make the definition (e.g. 'foo VARCHAR(30)') for this field.
00068                 field_output = [backend.quote_name(f.column), col_type]
00069                 field_output.append('%sNULL' % (not f.null and 'NOT ' or ''))
00070                 if f.unique and (not f.primary_key or backend.allows_unique_and_pk):
00071                         field_output.append('UNIQUE')
00072                 if f.primary_key:
00073                         field_output.append('PRIMARY KEY')
00074                 if tablespace and backend.supports_tablespaces and (f.unique or f.primary_key) and backend.autoindexes_primary_keys:
00075                         # We must specify the index tablespace inline, because we
00076                         # won't be generating a CREATE INDEX statement for this field.
00077                         field_output.append(backend.get_tablespace_sql(tablespace, inline=True))
00078                 if f.rel:
00079                         field_output.append('REFERENCES' + ' ' + \
00080                                 backend.quote_name(f.rel.to._meta.db_table) + ' (' + \
00081                                 backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column) + ')' +
00082                                 backend.get_deferrable_sql()
00083                         )
00084                 sql = "ALTER TABLE %s ADD COLUMN %s" % (backend.quote_name(opts.db_table), " ".join(field_output))
00085                 cursor.execute(sql)
00086         cursor.close()
00087 
def reset_models( *models ) :

def py::qodb::upgrade::resave_model (   model  ) 

redo entity.save() for all model entities.
00099                           :
00100         """
00101         redo entity.save() for all model entities.
00102         """
00103         for entity in model.objects.all() :
00104                 entity.save()
00105 
00106 @commit_on_success
def run( notifier ) :

def py::qodb::upgrade::reset_models (   models  ) 

Drop and re-create models
00088                             :
00089         """
00090         Drop and re-create models
00091         """
00092         cursor = connection.cursor()
00093         for model in models :
00094                 cursor.execute("DROP TABLE %s" % backend.quote_name(model._meta.db_table))
00095         cursor.close()
00096         from qodb.admin import syncdb
00097         syncdb()
00098 
def resave_model( model ) :

def py::qodb::upgrade::run (   notifier  ) 

00107                     :
00108         try :
00109                 info = DatabaseInfo.objects.all()[0]
00110         except IndexError :
00111                 DatabaseInfo.objects.create(version=QODB_VERSION)
00112                 info = DatabaseInfo.objects.all()[0]
00113         if info.version < QODB_VERSION :
00114                 for i in range(info.version+1, QODB_VERSION+1) :
00115                         globals()["upgrade_to_%d" % i](notifier)
00116                 info.version = QODB_VERSION
00117                 info.save()
00118 

def py::qodb::upgrade::upgrade_to_0 (   notifier  ) 

00040                              :
00041         notifier.grow(2)
00042         notifier.section(_("Updating database schema"))
00043         add_field(Series, "matching")
00044         add_field(Album, "matching")
00045         reset_models(AlbumCopy)
00046         notifier.section_end()
00047         notifier.section(_("Rebuilding tables"))
00048         resave_model(Series)
00049         resave_model(Album)
00050         notifier.section_end()
00051 
def add_field( model, *fields ) :

def py::qodb::upgrade::upgrade_to_1 (   notifier  ) 

00031                              :
00032         notifier.section(_("Updating database to schema %d") % 1)
00033         add_field(Author, "catalog")
00034         add_field(Editor, "catalog")
00035         add_field(Collection, "catalog")
00036         add_field(Series, "catalog")
00037         add_field(Album, "catalog")
00038         notifier.section_end()
00039 
def upgrade_to_0( notifier ) :

def py::qodb::upgrade::upgrade_to_2 (   notifier  ) 

00025                              :
00026         notifier.section(_("Updating database to schema %d") % 2)
00027         reset_models(UnderlayAuthor, UnderlayEditor, UnderlayCollection, UnderlaySeries, UnderlayAlbum, \
00028                                         Author, Album, Series, Collection, Editor)
00029         notifier.section_end()
00030 
def upgrade_to_1( notifier ) :


Generated on Tue Oct 9 20:40:33 2007 for Qomics by  doxygen 1.5.3