示例#1
0
    def forwards(self, orm):
        
        # Deleting field 'MessageLog.parent_id'
        #db.delete_foreign_key('message_log_messagelog', 'parent_id_id')
        db.delete_column('message_log_messagelog', 'parent_id_id')

        # Deleting field 'MessageLog.revision_after'
        db.delete_foreign_key('message_log_messagelog', 'revision_after_id')
        db.delete_column('message_log_messagelog', 'revision_after_id')

        # Deleting field 'MessageLog.revision_before'
        db.delete_foreign_key('message_log_messagelog', 'revision_before_id')
        db.delete_column('message_log_messagelog', 'revision_before_id')

        # Adding field 'MessageLog.revision'
        db.add_column('message_log_messagelog', 'revision', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['reversion.Revision'], null=True, blank=True), keep_default=False)

        # Adding field 'MessageLog.uuid'
        db.add_column('message_log_messagelog', 'uuid', self.gf('django.db.models.fields.CharField')(default='', max_length=36, db_index=True), keep_default=False)

        # Adding field 'MessageLog.parent_uuid'
        db.add_column('message_log_messagelog', 'parent_uuid', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=36, null=True, blank=True), keep_default=False)

        # Adding field 'MessageLog.group_uuid'
        db.add_column('message_log_messagelog', 'group_uuid', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=36, null=True, blank=True), keep_default=False)
示例#2
0
 def forwards(self, orm):
     # add temp field to be removed later
     db.add_column('maps_map', 'map_id', self.gf('django.db.models.fields.IntegerField')(default=1), keep_default=False)
     # Adding field 'Map.resourcebase_ptr_id'
     db.add_column('maps_map', 'resourcebase_ptr', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['base.ResourceBase'], null=True, blank=True), keep_default=False)
     # Removing maps_maplayer fk to maps_map.id
     db.delete_foreign_key('maps_maplayer', 'map_id')
示例#3
0
    def forwards(self, orm):

        db.delete_foreign_key('invapp_bagaction', 'bag_id')
        # Removing unique constraint on 'Bag', fields ['bagname']
        db.delete_primary_key('invapp_bag')

        # Adding field 'Bag.id'
        db.add_column(u'invapp_bag', u'id',
                      self.gf('django.db.models.fields.IntegerField')(primary_key=True, default=0),
                      keep_default=False)

        db.delete_column(u'invapp_bagaction', 'bag_id')

        db.add_column(u'invapp_bagaction', 'bag_id', self.gf('django.db.models.fields.IntegerField')(default=0))

        db.execute("CREATE SEQUENCE invapp_bag_id_seq")
        db.execute("ALTER TABLE invapp_bag ALTER COLUMN id "
                   "SET DEFAULT nextval('invapp_bag_id_seq'::regclass)")

        sql = db.foreign_key_sql('invapp_bagaction', 'bag_id', 'invapp_bag', 'id')
        db.execute(sql)

        # Changing field 'Bag.bagname'
        #db.alter_column(u'invapp_bag', 'bagname', self.gf('django.db.models.fields.TextField')())

        db.create_unique('invapp_bagaction', ['bag_id', 'action', 'timestamp'])
示例#4
0
 def forwards(self, orm):
     db.delete_foreign_key(u'logical_database', 'group_id')
     db.delete_unique(u'logical_database', ['group_id'])
     db.execute(
         "ALTER TABLE `logical_database` ADD CONSTRAINT `group_id_refs_id_1a2ad92c` FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`);"
     )
     db.create_index('logical_database', ['group_id'])
    def forwards(self, orm):
        
        # It's not a foreign key anymore, it's just a primary key field
        db.delete_foreign_key('pagelets_pagelet', 'pageletbase_ptr_id')
        db.alter_column('pagelets_pagelet', 'pageletbase_ptr_id', self.gf('django.db.models.fields.IntegerField')())

        # Renaming field 'Pagelet.pageletbase_ptr' to 'id'
        db.rename_column('pagelets_pagelet', 'pageletbase_ptr_id', 'id')

        # Adding field 'Pagelet.creation_date'
        db.add_column('pagelets_pagelet', 'creation_date', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Pagelet.created_by'
        db.add_column('pagelets_pagelet', 'created_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_pagelet_created', null=True, to=orm[user_orm_label]), keep_default=False)

        # Adding field 'Pagelet.last_changed'
        db.add_column('pagelets_pagelet', 'last_changed', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Pagelet.modified_by'
        db.add_column('pagelets_pagelet', 'modified_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_pagelet_last_modified', null=True, to=orm[user_orm_label]), keep_default=False)

        # Renaming field 'Page.pageletbase_ptr' to 'id'
        db.rename_column('pagelets_page', 'pageletbase_ptr_id', 'id')

        # Adding field 'Page.creation_date'
        db.add_column('pagelets_page', 'creation_date', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Page.created_by'
        db.add_column('pagelets_page', 'created_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_page_created', null=True, to=orm[user_orm_label]), keep_default=False)

        # Adding field 'Page.last_changed'
        db.add_column('pagelets_page', 'last_changed', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Page.modified_by'
        db.add_column('pagelets_page', 'modified_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_page_last_modified', null=True, to=orm[user_orm_label]), keep_default=False)
 def forwards(self, orm):
     # Foreign keys aren't enforced by default on our version of SQLite3, and
     # trying to delete them will throw an error. See:
     #   http://south.aeracode.org/ticket/775
     if db.backend_name != 'sqlite3':
         db.delete_foreign_key('course_overviews_courseoverviewtab',
                               'course_overview_id')
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_flash' ,'public_id')
     db.drop_primary_key("cmsplugin_flashpublic")
     db.rename_column("cmsplugin_flashpublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_flashpublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_flash", "flash_flash")
     db.rename_table("cmsplugin_flashpublic", "flash_publicflash")
     db.alter_column('cmsplugin_flash', 'public_id', orm['flash.flash:public'])
 def forwards(self, orm):
     db.delete_foreign_key('fccpublicfiles_politicalbuy', 'publicdocument_ptr_id')
     db.rename_column('fccpublicfiles_politicalbuy', 'publicdocument_ptr_id', 'id')
     db.execute_many('''
         create sequence fccpublicfiles_politicalbuy_id_seq;
         select setval('fccpublicfiles_politicalbuy_id_seq', max(id)) from fccpublicfiles_publicdocument;
         alter table fccpublicfiles_politicalbuy alter column id set default nextval('fccpublicfiles_politicalbuy_id_seq');
     ''')
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_googlemap' ,'public_id')
     db.drop_primary_key("cmsplugin_googlemappublic")
     db.rename_column("cmsplugin_googlemappublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_googlemappublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_googlemap", "googlemap_googlemap")
     db.rename_table("cmsplugin_googlemappublic", "googlemap_publicgooglemap")
     db.alter_column('cmsplugin_googlemap', 'public_id', orm['googlemap.googlemap:public'])
 def clean_constraints(t1, c1, t2, c2):
     # Workaround for http://south.aeracode.org/ticket/775
     if db.backend_name != "sqlite3":
         try:
             db.delete_foreign_key(t1, c1)
             db.execute(db.foreign_key_sql(t1, c1, t2, c2))
         except ValueError as e:
             print("Warning: Could not clean up constraints (this may be harmless): %s" % (e))
示例#11
0
 def backwards(self, orm):
     db.delete_foreign_key("cmsplugin_file", "public_id")
     db.drop_primary_key("cmsplugin_filepublic")
     db.rename_column("cmsplugin_filepublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_filepublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_file", "file_file")
     db.rename_table("cmsplugin_filepublic", "file_publicfile")
     db.alter_column("cmsplugin_file", "public_id", orm["file.file:public"])
示例#12
0
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_link' ,'public_id')
     db.drop_primary_key("cmsplugin_linkpublic")
     db.rename_column("cmsplugin_linkpublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_linkpublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_link", "link_link")
     db.rename_table("cmsplugin_linkpublic", "link_publiclink")
     db.alter_column('cmsplugin_link', 'public_id', orm['link.link:public'])
示例#13
0
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_snippetptr' ,'public_id')
     db.drop_primary_key("cmsplugin_snippetptrpublic")
     db.rename_column("cmsplugin_snippetptrpublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_snippetptrpublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_snippetptr", "snippet_snippetptr")
     db.rename_table("cmsplugin_snippetptrpublic", "snippet_publicsnippetptr")
     db.alter_column('cmsplugin_snippetptr', 'public_id', orm['snippet.snippetptr:public'])
示例#14
0
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_googlemap' ,'public_id')
     db.drop_primary_key("cmsplugin_googlemappublic")
     db.rename_column("cmsplugin_googlemappublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_googlemappublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_googlemap", "googlemap_googlemap")
     db.rename_table("cmsplugin_googlemappublic", "googlemap_publicgooglemap")
     db.alter_column('googlemap_googlemap', 'public_id', orm['googlemap.googlemap:public'])
示例#15
0
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_picture' ,'public_id')
     db.drop_primary_key("cmsplugin_picturepublic")
     db.rename_column("cmsplugin_picturepublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_picturepublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_picture", "picture_picture")
     db.rename_table("cmsplugin_picturepublic", "picture_publicpicture")
     db.alter_column('cmsplugin_picture', 'public_id', orm['picture.picture:public'])
    def forwards(self, orm):
        #if db.backend_name == 'sqlite3':
        #    return

        if db.backend_name != 'sqlite3':
            db.delete_foreign_key('Services_serviceaddress_services',
                                  'service_id')
        db.rename_column('Services_serviceaddress_services', 'service_id',
                         'user_id')
    def forwards(self, orm):
        if db.backend_name == 'sqlite3':
            return

        db.delete_foreign_key('Services_serviceaddress_services', 'service_id')

        sql = db.foreign_key_sql('Services_serviceaddress_services',
                                 'service_id', 'auth_user', 'id')
        db.execute(sql)
    def backwards(self, orm):
        if db.current_orm == 'sqlite3':
            return

        db.delete_foreign_key('Services_serviceaddress_services', 'service_id')

        sql = db.foreign_key_sql('Services_serviceaddress_services',
                                 'service_id', 'Service_services', 'id')
        db.execute(sql)
示例#19
0
 def forwards(self, orm):
     db.delete_foreign_key('fccpublicfiles_politicalbuy',
                           'publicdocument_ptr_id')
     db.rename_column('fccpublicfiles_politicalbuy',
                      'publicdocument_ptr_id', 'id')
     db.execute_many('''
         create sequence fccpublicfiles_politicalbuy_id_seq;
         select setval('fccpublicfiles_politicalbuy_id_seq', max(id)) from fccpublicfiles_publicdocument;
         alter table fccpublicfiles_politicalbuy alter column id set default nextval('fccpublicfiles_politicalbuy_id_seq');
     ''')
 def clean_constraints(t1, c1, t2, c2):
     # Workaround for http://south.aeracode.org/ticket/775
     if db.backend_name != "sqlite3":
         try:
             db.delete_foreign_key(t1, c1)
             db.execute(db.foreign_key_sql(t1, c1, t2, c2))
         except ValueError as e:
             print(
                 "Warning: Could not clean up constraints (this may be harmless): %s"
                 % (e))
示例#21
0
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_link', 'public_id')
     db.drop_primary_key("cmsplugin_linkpublic")
     db.rename_column("cmsplugin_linkpublic", "cmspluginpublic_ptr_id",
                      "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_linkpublic",
                           ("publiccmsplugin_ptr_id", ))
     db.rename_table("cmsplugin_link", "link_link")
     db.rename_table("cmsplugin_linkpublic", "link_publiclink")
     db.alter_column('link_link', 'public_id', orm['link.link:public'])
示例#22
0
 def backwards(self, orm): 
     db.delete_foreign_key('cmsplugin_text' ,'public_id')
     db.drop_primary_key("cmsplugin_textpublic")
     
     db.rename_column("cmsplugin_textpublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_textpublic", ("publiccmsplugin_ptr_id",))      
     db.foreign_key_sql('cmsplugin_text' ,'public_id', 'cmsplugin_textpublic', "publiccmsplugin_ptr_id")
     db.rename_table("cmsplugin_text", "text_text")
     db.rename_table("cmsplugin_textpublic", "text_publictext")
     db.alter_column('cmsplugin_text', 'public_id', orm['text.text:public'])
示例#23
0
 def backwards(self, orm):
     try:
         db.delete_foreign_key('cmsplugin_flash' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_flashpublic")
     db.rename_column("cmsplugin_flashpublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_flashpublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_flash", "flash_flash")
     db.rename_table("cmsplugin_flashpublic", "flash_publicflash")
     db.alter_column('flash_flash', 'public_id', orm['flash.flash:public'])
示例#24
0
 def backwards(self, orm):
     try:
         db.delete_foreign_key('cmsplugin_file' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_filepublic")
     db.rename_column("cmsplugin_filepublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_filepublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_file", "file_file")
     db.rename_table("cmsplugin_filepublic", "file_publicfile")
     db.alter_column('file_file', 'public_id', orm['file.file:public'])
 def forwards(self, orm):
     db.rename_table("text_text", "cmsplugin_text")
     db.rename_table("text_publictext", "cmsplugin_textpublic")
     db.rename_column("cmsplugin_textpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.alter_column("cmsplugin_text", "public_id", orm["text.text:public"])
     try:
         db.delete_foreign_key("cmsplugin_text", "public_id")
     except:
         pass
     db.drop_primary_key("cmsplugin_textpublic")
     db.create_primary_key("cmsplugin_textpublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql("cmsplugin_text", "public_id", "cmsplugin_textpublic", "cmspluginpublic_ptr_id")
示例#26
0
 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_snippetptr', 'public_id')
     db.drop_primary_key("cmsplugin_snippetptrpublic")
     db.rename_column("cmsplugin_snippetptrpublic",
                      "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_snippetptrpublic",
                           ("publiccmsplugin_ptr_id", ))
     db.rename_table("cmsplugin_snippetptr", "snippet_snippetptr")
     db.rename_table("cmsplugin_snippetptrpublic",
                     "snippet_publicsnippetptr")
     db.alter_column('snippet_snippetptr', 'public_id',
                     orm['snippet.snippetptr:public'])
示例#27
0
    def forwards(self, orm):

        db.rename_table("link_link", "cmsplugin_link")
        db.rename_table("link_publiclink", "cmsplugin_linkpublic")
        db.rename_column("cmsplugin_linkpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
        db.alter_column("cmsplugin_link", "public_id", orm["link.link:public"])
        try:
            db.delete_foreign_key("cmsplugin_link", "public_id")
        except:
            pass
        db.drop_primary_key("cmsplugin_linkpublic")
        db.create_primary_key("cmsplugin_linkpublic", ("cmspluginpublic_ptr_id",))
        db.foreign_key_sql("cmsplugin_link", "public_id", "cmsplugin_linkpublic", "cmspluginpublic_ptr_id")
示例#28
0
文件: db.py 项目: 10sr/hue
 def test_recursive_foreign_key_delete(self):
     """
     Test that recursive foreign keys are deleted correctly (see #1065)
     """
     Test = db.mock_model(model_name='Test', db_table='test_rec_fk_del',
                          db_tablespace='', pk_field_name='id',
                          pk_field_type=models.AutoField, pk_field_args=[])
     db.create_table('test_rec_fk_del', [
         ('id', models.AutoField(primary_key=True, auto_created=True)),
         ('fk', models.ForeignKey(Test)),
     ])
     db.execute_deferred_sql()
     db.delete_foreign_key('test_rec_fk_del', 'fk_id')
示例#29
0
 def forwards(self, orm):
     
     db.rename_table("picture_picture", "cmsplugin_picture")
     db.rename_table("picture_publicpicture", "cmsplugin_picturepublic")
     db.rename_column("cmsplugin_picturepublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.alter_column('cmsplugin_picture', 'public_id', orm['picture.picture:public'])
     try:
         db.delete_foreign_key('cmsplugin_picture' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_picturepublic")
     db.create_primary_key("cmsplugin_picturepublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql('cmsplugin_picture' ,'public_id', 'cmsplugin_picturepublic', 'cmspluginpublic_ptr_id')
示例#30
0
    def forwards(self, orm):    
        db.rename_table("text_text", "cmsplugin_text")
        db.rename_table("text_publictext", "cmsplugin_textpublic")
        db.rename_column("cmsplugin_textpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
        db.alter_column('cmsplugin_text', 'public_id', orm['text.text:public'])
        try:
            db.delete_foreign_key('cmsplugin_text' ,'public_id')
        except:
            pass

        db.drop_primary_key("cmsplugin_textpublic")  
        db.create_primary_key("cmsplugin_textpublic", ("cmspluginpublic_ptr_id",))
        db.foreign_key_sql('cmsplugin_text' ,'public_id', 'cmsplugin_textpublic', 'cmspluginpublic_ptr_id')
示例#31
0
文件: db.py 项目: lmorchard/whuru
 def test_recursive_foreign_key_delete(self):
     """
     Test that recursive foreign keys are deleted correctly (see #1065)
     """
     Test = db.mock_model(model_name='Test', db_table='test_rec_fk_del',
                          db_tablespace='', pk_field_name='id',
                          pk_field_type=models.AutoField, pk_field_args=[])
     db.create_table('test_rec_fk_del', [
         ('id', models.AutoField(primary_key=True, auto_created=True)),
         ('fk', models.ForeignKey(Test)),
     ])
     db.execute_deferred_sql()
     db.delete_foreign_key('test_rec_fk_del', 'fk_id')
示例#32
0
    def forwards(self, orm):
        # Deleting field 'Category.label'
        db.delete_column('events_category', 'label')

        # Removing M2M table for field labels on 'Category'
        db.delete_table(db.shorten_name('events_category_labels'))

        # Adding M2M table for field alt_labels on 'Category'
        m2m_table_name = db.shorten_name('events_category_alt_labels')
        db.create_table(
            m2m_table_name,
            (('id',
              models.AutoField(
                  verbose_name='ID', primary_key=True, auto_created=True)),
             ('category', models.ForeignKey(orm['events.category'],
                                            null=False)),
             ('categorylabel',
              models.ForeignKey(orm['events.categorylabel'], null=False))))
        db.create_unique(m2m_table_name, ['category_id', 'categorylabel_id'])

        # Deleting field 'CategoryLabel.data_source'
        db.delete_column('events_categorylabel', 'data_source_id')

        # Deleting field 'CategoryLabel.created_by'
        db.delete_column('events_categorylabel', 'created_by_id')

        # Deleting field 'CategoryLabel.origin_id'
        db.delete_column('events_categorylabel', 'origin_id')

        # Deleting field 'CategoryLabel.modified_by'
        db.delete_column('events_categorylabel', 'modified_by_id')

        # Deleting field 'Language.code'
        db.delete_column('events_language', 'code')

        db.delete_foreign_key('events_event', 'language_id')

        # Changing field 'Language.id'
        db.alter_column(
            'events_language', 'id',
            self.gf('django.db.models.fields.CharField')(primary_key=True,
                                                         max_length=6))

        # Adding field 'CategoryLabel.language'
        db.add_column('events_categorylabel',
                      'language',
                      self.gf('django.db.models.fields.related.ForeignKey')(
                          default='fi', to=orm['events.Language']),
                      keep_default=False)
 def forwards(self, orm):
     try:
         db.delete_foreign_key('sentry_message', 'group_id')
         db.delete_foreign_key('sentry_message', 'project_id')
         db.delete_foreign_key('sentry_eventmapping', 'group_id')
         db.delete_foreign_key('sentry_eventmapping', 'project_id')
     except OperationalError:
         pass
    def forwards(self, orm):
        # OMFG Get ready, we're going to change the primary key!
        # Doing bad things, disabling triggers
        db.execute("ALTER TABLE brainstorm_idea DISABLE TRIGGER ALL;")

        # Dropping foreign key constraint
        db.delete_foreign_key('brainstorm_idea', 'subsite_id')
        db.execute('DROP INDEX brainstorm_idea_subsite_id_like')
        db.delete_index('brainstorm_idea', ['subsite_id'])

        # Removing primary key on 'Subsite', fields ['slug']
        db.delete_primary_key(u'brainstorm_subsite')

        # Adding primary key field 'Subsite.id'
        db.add_column(u'brainstorm_subsite', u'id',
                      self.gf('django.db.models.fields.IntegerField')(blank=True, null=True))

        # WOW. Have to manually create AutoFields. Thanks Django!
        db.execute('CREATE SEQUENCE brainstorm_subsite_id_seq;')
        db.execute("UPDATE brainstorm_subsite SET id = nextval('brainstorm_subsite_id_seq');")
        db.execute("ALTER TABLE brainstorm_subsite ALTER COLUMN id SET DEFAULT nextval('brainstorm_subsite_id_seq');")
        db.execute('ALTER SEQUENCE brainstorm_subsite_id_seq OWNED BY brainstorm_subsite.id;')
        db.execute("SELECT setval('brainstorm_subsite_id_seq', q.i) FROM(SELECT MAX(id) i FROM brainstorm_subsite) q;")

        # Now make it the pk
        db.create_primary_key('brainstorm_subsite', ['id'])

        # Updating foreign key values
        db.execute('''UPDATE brainstorm_idea idea
                      SET subsite_id = subsite.id
                      FROM brainstorm_subsite subsite
                      WHERE(idea.subsite_id = subsite.slug);''')

        # Casting the fk to an integer
        db.execute("ALTER TABLE brainstorm_idea ALTER COLUMN subsite_id TYPE integer USING CAST(subsite_id AS integer);")

        # Re-adding foreign key constraint
        fk_sql = db.foreign_key_sql('brainstorm_idea', 'subsite_id', 'brainstorm_subsite', 'id')
        db.execute(fk_sql)

        # Changing field 'Subsite.slug' to a plain old slugfield
        db.alter_column(u'brainstorm_subsite', 'slug', self.gf('django.db.models.fields.SlugField')(max_length=50))

        # Adding unique constraint on 'Subsite', fields ['slug']
        db.create_unique(u'brainstorm_subsite', ['slug'])

        # Re-enabling triggers
        db.execute("ALTER TABLE brainstorm_idea ENABLE TRIGGER ALL;")
示例#35
0
def delete_dynamic_tables(*names):
    db.start_transaction()
    for model in get_dynamic_models(*names):
        for f in model._meta.fields:
            if isinstance(f, models.ForeignKey):
                try:
                    db.delete_foreign_key(model._meta.db_table, f.column)
                except ValueError:
                    pass
    transaction.commit_unless_managed()

    db.start_transaction()
    for model in get_dynamic_models(*names):
        db.delete_table(model._meta.db_table, cascade=True)
    #db.commit_transaction()
    transaction.commit_unless_managed()
示例#36
0
def delete_dynamic_tables(*names):
    db.start_transaction()
    for model in get_dynamic_models(*names):
        for f in model._meta.fields:
            if isinstance(f, models.ForeignKey):
                try:
                    db.delete_foreign_key(model._meta.db_table, f.column)
                except ValueError:
                    pass
    transaction.commit_unless_managed()

    db.start_transaction()
    for model in get_dynamic_models(*names):
        db.delete_table(model._meta.db_table, cascade=True)
    #db.commit_transaction()
    transaction.commit_unless_managed()
示例#37
0
    def forwards(self, orm):

        # Changing field 'Location.room'
        try:
            db.delete_foreign_key('healers_location', 'room_id')
        except Exception:
            #sqllite
            pass
        db.delete_column('healers_location', 'room_id')
        db.add_column(
            'healers_location', 'room',
            self.gf('django.db.models.fields.CharField')(default='',
                                                         max_length=12))

        # Deleting model 'Room'
        db.delete_table('healers_room')
    def backwards(self, orm):
        db.rename_table('socialmedia_socialmedia', 'utils_socialmedia')

        if not db.dry_run:
            # For permissions to work properly after migrating
            orm['contenttypes.contenttype'].objects.filter(app_label='socialmedia', model='socialmedia').update(app_label='utils')

            # Fix foreign key for accounts
            db.delete_foreign_key('accounts_account_social_media', 'socialmedia_id')
            sql = db.foreign_key_sql('accounts_account_social_media', 'socialmedia_id', 'utils_socialmedia', 'id')
            db.execute(sql)

            # Fix foreign key for contacts
            db.delete_foreign_key('contacts_contact_social_media', 'socialmedia_id')
            sql = db.foreign_key_sql('contacts_contact_social_media', 'socialmedia_id', 'utils_socialmedia', 'id')
            db.execute(sql)
    def forwards(self, orm):
        if (db.backend_name == 'mysql'):
            #case mysql db it is necessary :/
            db.delete_foreign_key('chat_userlinks', 'user_id')
            db.delete_foreign_key('chat_userlinks', 'link_id')

        # Removing unique constraint on 'UserLinks', fields ['user']
        db.delete_unique('chat_userlinks', ['user_id'])

        # Removing unique constraint on 'UserLinks', fields ['link']
        db.delete_unique('chat_userlinks', ['link_id'])

        # Changing field 'UserLinks.link'
        db.alter_column('chat_userlinks', 'link_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['chat.Links']))

        # Changing field 'UserLinks.user'
        db.alter_column('chat_userlinks', 'user_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User']))
示例#40
0
def innodb_ready_rename_column(orm, models, table, old_column_name,
                               new_column_name, app_model, new_field_name):
    """
    Foreign key renaming which works for InnoDB
    More: http://south.aeracode.org/ticket/466

    Parameters:
    - orm: a reference to 'orm' parameter passed to Migration.forwards()/backwards()
    - models: reference to Migration.models data structure
    - table: e.g. 'askbot_thread'
    - old_column_name: e.g. 'question_post_id'
    - new_column_name: e.g. 'question_id'
    - app_model: e.g. 'askbot.thread' (should be a dict key into 'models')
    - new_field_name: e.g. 'question' (usually it's same as new_column_name, only without trailing '_id')
    """
    use_workaround = houston_do_we_have_a_problem(table)

    # ditch the foreign key
    if use_workaround:
        db.delete_foreign_key(table, old_column_name)

    # rename column
    db.rename_column(table, old_column_name, new_column_name)

    # restore the foreign key
    if not use_workaround:
        return

    model_def = models[app_model][new_field_name]
    assert model_def[0] == 'django.db.models.fields.related.ForeignKey'
    # Copy the dict so that we don't change the original
    # (otherwise the dry run would change it for the "normal" run
    #  and the latter would try to convert str to model once again)
    fkey_params = model_def[2].copy()
    assert 'to' in fkey_params
    assert fkey_params['to'].startswith("orm['")
    assert fkey_params['to'].endswith("']")
    fkey_params['to'] = orm[fkey_params['to'][
        5:-2]]  # convert "orm['app.models']" string to actual model
    field = ask_for_it_by_name(model_def[0])(**fkey_params)
    # INFO: ask_for_it_by_name() if equivalent to self.gf() which is usually used in migrations, e.g.:
    #          db.alter_column('askbot_badgedata', 'slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50))
    db.alter_column(table, new_column_name, field)
    db.clear_deferred_sql()
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Don't use "from appname.models import ModelName".
        # Use orm.ModelName to refer to models in this application,
        # and orm['appname.ModelName'] for models in other applications.

        db.delete_foreign_key('vkontakte_photos_album', 'owner_id')
        db.delete_foreign_key('vkontakte_photos_photo', 'owner_id')

        group_ct_id = ContentType.objects.get(app_label='vkontakte_groups', model='group').id
        user_ct_id = ContentType.objects.get(app_label='vkontakte_users', model='user').id

        # Migrate Album

        albums = orm.Album.objects.all()

        for a in albums:
            if a.group:
                a.owner_id = a.group.pk
                a.owner_content_type_id = group_ct_id
            elif a.owner_id:
                # owner_id already set
                a.owner_content_type_id = user_ct_id
            else:
                print "bad record %s" % a.remote_id

            a.save()

        # Migrate Photo
        photos = orm.Photo.objects.all()

        for p in photos:
            if p.group:
                p.owner_id = p.group.pk
                p.owner_content_type_id = group_ct_id
            elif p.owner_id:
                # owner_id already set
                p.owner_content_type_id = user_ct_id
            else:
                print "bad record %s" % p.remote_id

            p.save()
示例#42
0
def innodb_ready_rename_column(orm, models, table, old_column_name, new_column_name, app_model, new_field_name):
    """
    Foreign key renaming which works for InnoDB
    More: http://south.aeracode.org/ticket/466

    Parameters:
    - orm: a reference to 'orm' parameter passed to Migration.forwards()/backwards()
    - models: reference to Migration.models data structure
    - table: e.g. 'askbot_thread'
    - old_column_name: e.g. 'question_post_id'
    - new_column_name: e.g. 'question_id'
    - app_model: e.g. 'askbot.thread' (should be a dict key into 'models')
    - new_field_name: e.g. 'question' (usually it's same as new_column_name, only without trailing '_id')
    """
    use_workaround = houston_do_we_have_a_problem(table)

    # ditch the foreign key
    if use_workaround:
        db.delete_foreign_key(table, old_column_name)

    # rename column
    db.rename_column(table, old_column_name, new_column_name)

    # restore the foreign key
    if not use_workaround:
        return

    model_def = models[app_model][new_field_name]
    assert model_def[0] == "django.db.models.fields.related.ForeignKey"
    # Copy the dict so that we don't change the original
    # (otherwise the dry run would change it for the "normal" run
    #  and the latter would try to convert str to model once again)
    fkey_params = model_def[2].copy()
    assert "to" in fkey_params
    assert fkey_params["to"].startswith("orm['")
    assert fkey_params["to"].endswith("']")
    fkey_params["to"] = orm[fkey_params["to"][5:-2]]  # convert "orm['app.models']" string to actual model
    field = ask_for_it_by_name(model_def[0])(**fkey_params)
    # INFO: ask_for_it_by_name() if equivalent to self.gf() which is usually used in migrations, e.g.:
    #          db.alter_column('askbot_badgedata', 'slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50))
    db.alter_column(table, new_column_name, field)
    db.clear_deferred_sql()
    def forwards(self, orm):
        db.create_table('section_sectioncontentmapping', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('old_id', self.gf('django.db.models.fields.IntegerField')(unique=True)),
            ('new_id', self.gf('django.db.models.fields.IntegerField')(unique=True)),
        ))

        if not table_exists('microsite_microsite'):
            # Deleting model 'Section'
            db.delete_table('section_section')
        else:
            # Adding field 'MicroSite.basesection_ptr'
            db.add_column('microsite_microsite', 'basesection_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['section.BaseSection'], null=True), keep_default=False)
            if db.backend_name not in ['sqlite3', 'mysql']:
                db.delete_foreign_key('section_section', 'basesection_ptr_id')

        # Adding field 'BaseSection.basecontent_ptr'
        db.add_column('section_basesection', 'basecontent_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['base.BaseContent'], null=True), keep_default=False)
        if db.backend_name not in ['sqlite3', 'mysql']:
            db.delete_foreign_key('section_basesection_related_content', 'basesection_id')
示例#44
0
    def forwards(self, orm):
        "Write your forwards methods here."
        if db.backend_name != 'sqlite3':
            db.alter_column(
                'job_trainensemble', 'file_id_id',
                models.ForeignKey(orm['data_management.DataFile'],
                                  null=True,
                                  blank=True))

            db.delete_foreign_key('job_trainensemble', 'test_dataset_id')
            db.alter_column(
                'job_trainensemble', 'test_dataset_id',
                models.ForeignKey(orm['data_management.DataFile'],
                                  null=True,
                                  blank=True))

            db.delete_foreign_key('job_trainensemble', 'valid_dataset_id')
            db.alter_column(
                'job_trainensemble', 'valid_dataset_id',
                models.ForeignKey(orm['data_management.DataFile'],
                                  null=True,
                                  blank=True))

            db.delete_foreign_key('job_predictensemble', 'file_id_id')
            db.alter_column(
                'job_predictensemble', 'file_id_id',
                models.ForeignKey(orm['data_management.DataFile'],
                                  null=True,
                                  blank=True))
    def forwards(self, orm):
        "Make remote_id Primary Key"

        # Remove PK from Album
        db.delete_foreign_key('vkontakte_photos_photo', 'album_id')

        photos = orm.Photo.objects.only('album').all()  #

        for p in photos:
            album = orm.Album.objects.get(id=p.album_id)
            p.album_id = album.remote_id
            p.save()

        db.delete_primary_key('vkontakte_photos_album')
        #db.delete_column(u'vkontakte_photos_album', u'id')

        db.create_primary_key('vkontakte_photos_album', ['remote_id'])
        db.alter_column('vkontakte_photos_photo', 'album_id', models.ForeignKey(
            orm['vkontakte_photos.Album'], null=True, blank=True))

        # Remove PK from Photo
        # Remove Foreign key from Comments and likes
        db.delete_foreign_key('vkontakte_photos_comment', 'photo_id')
        db.delete_foreign_key('vkontakte_photos_photo_like_users', 'photo_id')

        db.delete_primary_key('vkontakte_photos_photo')
        #db.delete_column(u'vkontakte_photos_photo', u'id')

        # Create Primary Keys
        db.create_primary_key('vkontakte_photos_photo', ['remote_id'])
示例#46
0
    def forwards(self, orm):
        "Make remote_id Primary Key"

        # Remove PK from Album
        db.delete_foreign_key('vkontakte_photos_photo', 'album_id')

        photos = orm.Photo.objects.only('album').all()  #

        for p in photos:
            album = orm.Album.objects.get(id=p.album_id)
            p.album_id = album.remote_id
            p.save()

        db.delete_primary_key('vkontakte_photos_album')
        #db.delete_column(u'vkontakte_photos_album', u'id')

        db.create_primary_key('vkontakte_photos_album', ['remote_id'])
        db.alter_column(
            'vkontakte_photos_photo', 'album_id',
            models.ForeignKey(orm['vkontakte_photos.Album'],
                              null=True,
                              blank=True))

        # Remove PK from Photo
        # Remove Foreign key from Comments and likes
        db.delete_foreign_key('vkontakte_photos_comment', 'photo_id')
        db.delete_foreign_key('vkontakte_photos_photo_like_users', 'photo_id')

        db.delete_primary_key('vkontakte_photos_photo')
        #db.delete_column(u'vkontakte_photos_photo', u'id')

        # Create Primary Keys
        db.create_primary_key('vkontakte_photos_photo', ['remote_id'])
示例#47
0
    def backwards(self, orm):
        
        # Adding field 'MessageLog.parent_id'
        db.add_column('message_log_messagelog', 'parent_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['message_log.MessageLog'], null=True, blank=True), keep_default=False)

        # Adding field 'MessageLog.revision_after'
        db.add_column('message_log_messagelog', 'revision_after', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pre_message', null=True, to=orm['revision.Revision']), keep_default=False)

        # Adding field 'MessageLog.revision_before'
        db.add_column('message_log_messagelog', 'revision_before', self.gf('django.db.models.fields.related.ForeignKey')(related_name='post_message', null=True, to=orm['revision.Revision']), keep_default=False)

        # Deleting field 'MessageLog.revision'
        db.delete_foreign_key('message_log_messagelog', 'revision_id')
        db.delete_column('message_log_messagelog', 'revision_id')

        # Deleting field 'MessageLog.uuid'
        db.delete_column('message_log_messagelog', 'uuid')

        # Deleting field 'MessageLog.parent_uuid'
        db.delete_column('message_log_messagelog', 'parent_uuid')

        # Deleting field 'MessageLog.group_uuid'
        db.delete_column('message_log_messagelog', 'group_uuid')
示例#48
0
    def forwards(self, orm):
        if (db.backend_name == 'mysql'):
            #case mysql db it is necessary :/
            db.delete_foreign_key('chat_userlinks', 'user_id')
            db.delete_foreign_key('chat_userlinks', 'link_id')

        # Removing unique constraint on 'UserLinks', fields ['user']
        db.delete_unique('chat_userlinks', ['user_id'])

        # Removing unique constraint on 'UserLinks', fields ['link']
        db.delete_unique('chat_userlinks', ['link_id'])

        # Changing field 'UserLinks.link'
        db.alter_column(
            'chat_userlinks', 'link_id',
            self.gf('django.db.models.fields.related.ForeignKey')(
                to=orm['chat.Links']))

        # Changing field 'UserLinks.user'
        db.alter_column(
            'chat_userlinks', 'user_id',
            self.gf('django.db.models.fields.related.ForeignKey')(
                to=orm['auth.User']))
示例#49
0
    def forwards(self, orm):
        # Removing unique constraint on 'Order', fields ['user']
        # Removes foreign key constraint first so that the index can be deleted
        # Uses code snippet from db.alter_column method to handle adding it back
        storage_order_user_field = self.gf('django.db.models.fields.related.ForeignKey')(related_name='order', to=orm['auth.User'])
        db.delete_foreign_key('storage_order', 'user_id')
        db.delete_unique('storage_order', ['user_id'])
        if db.supports_foreign_keys:
            db.execute(
                db.foreign_key_sql(
                    'storage_order',
                    'user_id',
                    storage_order_user_field.rel.to._meta.db_table,
                    storage_order_user_field.rel.to._meta.get_field(storage_order_user_field.rel.field_name).column
                )
            )

        # Adding field 'Order.year'
        db.add_column('storage_order', 'year',
                      self.gf('django.db.models.fields.IntegerField')(default=2012),
                      keep_default=False)

        # Adding field 'DropoffPickupTime.year'
        db.add_column('storage_dropoffpickuptime', 'year',
                      self.gf('django.db.models.fields.IntegerField')(default=2012),
                      keep_default=False)

        # Adding field 'UnpaidOrder.year'
        db.add_column('storage_unpaidorder', 'year',
                      self.gf('django.db.models.fields.IntegerField')(default=2012),
                      keep_default=False)

        # Adding field 'Post.visible'
        db.add_column('storage_post', 'visible',
                      self.gf('django.db.models.fields.BooleanField')(default=True),
                      keep_default=False)
示例#50
0
    def backwards(self, orm):

        db.delete_foreign_key('invapp_bagaction', 'bag_id')

        db.delete_primary_key('invapp_bag')

        # Deleting field 'Bag.id'
        db.delete_column(u'invapp_bag', u'id')

        db.execute('DROP SEQUENCE invapp_bag_id_seq')

        # Changing field 'Bag.bagname'
        db.alter_column(u'invapp_bag', 'bagname', self.gf('django.db.models.fields.TextField')(primary_key=True))

        db.create_primary_key(u'invapp_bag', ['bagname'])

        db.delete_column(u'invapp_bagaction', 'bag_id')

        db.add_column(u'invapp_bagaction', 'bag_id', self.gf('django.db.models.fields.TextField')())

        sql = db.foreign_key_sql('invapp_bagaction', 'bag_id', 'invapp_bag', 'bagname')
        db.execute(sql)

        db.create_unique('invapp_bagaction', ['bag_id', 'action', 'timestamp'])
    def forwards(self, orm):
        # Changing field 'AssetCategory.id' (serial)
        # to 'AssetCategory.slug' (slugfield)
        db.add_column('ralph_assets_assetcategory', 'slug',
                      self.gf('django.db.models.fields.SlugField')(default='slug',
                      unique=False, max_length=100),
                      keep_default=False)
        db.add_column('ralph_assets_asset', 'category_new_id',
                      self.gf('django.db.models.fields.SlugField')(null=True,
                      unique=False, max_length=100, db_index=False))
        db.add_column('ralph_assets_assetcategory', 'parent_new_id',
                      self.gf('django.db.models.fields.SlugField')(null=True,
                      unique=False, max_length=100, db_index=False))
        db.add_column('ralph_assets_assetmodel', 'category_new_id',
                      self.gf('django.db.models.fields.SlugField')(null=True,
                      unique=False, max_length=100, db_index=False))

        db.start_transaction()

        for id in db.execute(
            'SELECT id FROM ralph_assets_assetcategory WHERE parent_id IS NULL'):
            self.update_slug_and_child(id)

        db.commit_transaction()

        db.create_unique(u'ralph_assets_assetcategory', ['slug'])
        db.delete_foreign_key("ralph_assets_asset", "category_id")
        db.delete_foreign_key("ralph_assets_assetmodel", "category_id")
        db.delete_foreign_key("ralph_assets_assetcategory", "parent_id")
        db.delete_column('ralph_assets_assetcategory', 'parent_id')
        db.delete_column('ralph_assets_assetcategory', 'id')
        db.create_primary_key("ralph_assets_assetcategory", ["slug"])
        db.send_create_signal('ralph_assets', ['ralph_assets_assetcategory'])
        db.rename_column('ralph_assets_assetcategory', 'parent_new_id', 'parent_id')
        db.delete_column('ralph_assets_asset', 'category_id')
        db.rename_column('ralph_assets_asset', 'category_new_id', 'category_id')
        db.delete_column('ralph_assets_assetmodel', 'category_id')
        db.rename_column('ralph_assets_assetmodel', 'category_new_id', 'category_id')
        db.create_index('ralph_assets_assetcategory', ['parent_id'], unique=False)
        db.create_index('ralph_assets_asset', ['category_id'], unique=False)
        db.create_index('ralph_assets_assetmodel', ['category_id'], unique=False)
        sql = db.foreign_key_sql('ralph_assets_asset',
            'category_id', 'ralph_assets_assetcategory', 'slug')
        db.execute(sql)
        sql = db.foreign_key_sql('ralph_assets_assetmodel',
            'category_id', 'ralph_assets_assetcategory', 'slug')
        db.execute(sql)
        sql = db.foreign_key_sql('ralph_assets_assetcategory',
            'parent_id', 'ralph_assets_assetcategory', 'slug')
        db.execute(sql)
        try:
            db.delete_unique('ralph_assets_assetcategory', ['name'])
        except ValueError:
            pass
示例#52
0
    def forwards(self, orm):
        # on some systmes this constraint is created.
        try:
            db.delete_foreign_key('tko_iteration_result', 'test_idx')
        except ValueError:
            logging.warning(
                "Failed to delete foreign key on tko_interation_result, it likely doesn't exist"
            )

        # Removing primary key constraint on tko_iteration_result, allowing more than one keval per test
        db.delete_primary_key('tko_iteration_result')
        db.create_index('tko_iteration_result', ['test_idx'])
        create_perf_view = """
        CREATE OR REPLACE VIEW `tko_perf_view` AS
          SELECT `tko_tests`.`test_idx` AS `test_idx`,
          `tko_tests`.`job_idx` AS `job_idx`,
          `tko_tests`.`test` AS `test`,
          `tko_tests`.`subdir` AS `subdir`,
          `tko_tests`.`kernel_idx` AS `kernel_idx`,
          `tko_tests`.`status` AS `status`,`tko_tests`.`reason` AS `reason`,
          `tko_tests`.`machine_idx` AS `machine_idx`,
          `tko_tests`.`started_time` AS `test_started_time`,
          `tko_tests`.`finished_time` AS `test_finished_time`,
          `tko_jobs`.`tag` AS `job_tag`,
          `tko_jobs`.`label` AS `job_label`,
          `tko_jobs`.`username` AS `job_username`,
          `tko_jobs`.`queued_time` AS `job_queued_time`,
          `tko_jobs`.`started_time` AS `job_started_time`,
          `tko_jobs`.`finished_time` AS `job_finished_time`,
          `tko_machines`.`hostname` AS `machine_hostname`,
          `tko_machines`.`machine_group` AS `machine_group`,
          `tko_machines`.`owner` AS `machine_owner`,
          `tko_kernels`.`kernel_hash` AS `kernel_hash`,
          `tko_kernels`.`base` AS `kernel_base`,
          `tko_kernels`.`printable` AS `kernel_printable`,
          `tko_status`.`word` AS `status_word`,
          `tko_iteration_result`.`iteration` AS `iteration`,
          `tko_iteration_result`.`attribute` AS `iteration_key`,
          `tko_iteration_result`.`value` AS `iteration_value`
          FROM
          (
            (
              (
                (
                  (
                  `tko_tests` join `tko_jobs` ON
                    ((`tko_jobs`.`job_idx` = `tko_tests`.`job_idx`)))
                  JOIN `tko_machines` ON
                    ((`tko_machines`.`machine_idx` = `tko_jobs`.`machine_idx`))
                )
               JOIN `tko_kernels` ON
                ((`tko_kernels`.`kernel_idx` = `tko_tests`.`kernel_idx`))
              )
              JOIN `tko_status` on
                ((`tko_status`.`status_idx` = `tko_tests`.`status`))
            )
            JOIN `tko_iteration_result` ON
              ((`tko_iteration_result`.`test_idx` = `tko_tests`.`test_idx`))
          );
        """
        db.execute(create_perf_view)

        create_perf_view_2 = """
        CREATE OR REPLACE VIEW `tko_perf_view_2` AS
          SELECT `tko_tests`.`test_idx` AS `test_idx`,
          `tko_tests`.`job_idx` AS `job_idx`,
          `tko_tests`.`test` AS `test_name`,
          `tko_tests`.`subdir` AS `subdir`,
          `tko_tests`.`kernel_idx` AS `kernel_idx`,
          `tko_tests`.`status` AS `status_idx`,
          `tko_tests`.`reason` AS `reason`,
          `tko_tests`.`machine_idx` AS `machine_idx`,
          `tko_tests`.`started_time` AS `test_started_time`,
          `tko_tests`.`finished_time` AS `test_finished_time`,
          `tko_jobs`.`tag` AS `job_tag`,
          `tko_jobs`.`label` AS `job_name`,
          `tko_jobs`.`username` AS `job_owner`,
          `tko_jobs`.`queued_time` AS `job_queued_time`,
          `tko_jobs`.`started_time` AS `job_started_time`,
          `tko_jobs`.`finished_time` AS `job_finished_time`,
          `tko_machines`.`hostname` AS `hostname`,
          `tko_machines`.`machine_group` AS `platform`,
          `tko_machines`.`owner` AS `machine_owner`,
          `tko_kernels`.`kernel_hash` AS `kernel_hash`,
          `tko_kernels`.`base` AS `kernel_base`,
          `tko_kernels`.`printable` AS `kernel`,
          `tko_status`.`word` AS `status`,
          `tko_iteration_result`.`iteration` AS `iteration`,
          `tko_iteration_result`.`attribute` AS `iteration_key`,
          `tko_iteration_result`.`value` AS `iteration_value`
        FROM
        (
          (
            (
              (
                (
                  `tko_tests` LEFT JOIN `tko_jobs` ON
                    ((`tko_jobs`.`job_idx` = `tko_tests`.`job_idx`))
                )
                LEFT JOIN `tko_machines` ON
                  ((`tko_machines`.`machine_idx` = `tko_jobs`.`machine_idx`))
              )
              LEFT JOIN `tko_kernels` ON
              ((`tko_kernels`.`kernel_idx` = `tko_tests`.`kernel_idx`))
            )
            LEFT JOIN `tko_status` ON
            ((`tko_status`.`status_idx` = `tko_tests`.`status`))
          )
          LEFT JOIN `tko_iteration_result` ON
            ((`tko_iteration_result`.`test_idx` = `tko_tests`.`test_idx`))
        )
        """
        db.execute(create_perf_view_2)
示例#53
0
 def forwards(self, orm):
     # drop FK to user to avoid deadlocks.
     db.delete_foreign_key("django_kissmetrics_events", "user_id")
 def forwards(self, orm):
     db.delete_foreign_key(u'logical_database', 'group_id')
     db.delete_unique(u'logical_database', ['group_id'])
     db.execute("ALTER TABLE `logical_database` ADD CONSTRAINT `group_id_refs_id_1a2ad92c` FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`);")
     db.create_index('logical_database', ['group_id'])
def migrate_fk(table, field='owner_id', to_table='accounts_hierarchicuser',
               to_field='id'):
    db.delete_foreign_key(table, field)
    sql = db.foreign_key_sql(table, field,
                             to_table, to_field)
    db.execute(sql)
示例#56
0
 def backwards(self, orm):
     db.delete_foreign_key("santiago_buyin", "table_id")
示例#57
0
    def forwards(self, orm):
        # OMFG Get ready, we're going to change the primary key!
        # Doing bad things, disabling triggers
        db.execute("ALTER TABLE brainstorm_idea DISABLE TRIGGER ALL;")

        # Dropping foreign key constraint
        db.delete_foreign_key('brainstorm_idea', 'subsite_id')
        db.execute('DROP INDEX brainstorm_idea_subsite_id_like')
        db.delete_index('brainstorm_idea', ['subsite_id'])

        # Removing primary key on 'Subsite', fields ['slug']
        db.delete_primary_key(u'brainstorm_subsite')

        # Adding primary key field 'Subsite.id'
        db.add_column(
            u'brainstorm_subsite', u'id',
            self.gf('django.db.models.fields.IntegerField')(blank=True,
                                                            null=True))

        # WOW. Have to manually create AutoFields. Thanks Django!
        db.execute('CREATE SEQUENCE brainstorm_subsite_id_seq;')
        db.execute(
            "UPDATE brainstorm_subsite SET id = nextval('brainstorm_subsite_id_seq');"
        )
        db.execute(
            "ALTER TABLE brainstorm_subsite ALTER COLUMN id SET DEFAULT nextval('brainstorm_subsite_id_seq');"
        )
        db.execute(
            'ALTER SEQUENCE brainstorm_subsite_id_seq OWNED BY brainstorm_subsite.id;'
        )
        db.execute(
            "SELECT setval('brainstorm_subsite_id_seq', q.i) FROM(SELECT MAX(id) i FROM brainstorm_subsite) q;"
        )

        # Now make it the pk
        db.create_primary_key('brainstorm_subsite', ['id'])

        # Updating foreign key values
        db.execute('''UPDATE brainstorm_idea idea
                      SET subsite_id = subsite.id
                      FROM brainstorm_subsite subsite
                      WHERE(idea.subsite_id = subsite.slug);''')

        # Casting the fk to an integer
        db.execute(
            "ALTER TABLE brainstorm_idea ALTER COLUMN subsite_id TYPE integer USING CAST(subsite_id AS integer);"
        )

        # Re-adding foreign key constraint
        fk_sql = db.foreign_key_sql('brainstorm_idea', 'subsite_id',
                                    'brainstorm_subsite', 'id')
        db.execute(fk_sql)

        # Changing field 'Subsite.slug' to a plain old slugfield
        db.alter_column(
            u'brainstorm_subsite', 'slug',
            self.gf('django.db.models.fields.SlugField')(max_length=50))

        # Adding unique constraint on 'Subsite', fields ['slug']
        db.create_unique(u'brainstorm_subsite', ['slug'])

        # Re-enabling triggers
        db.execute("ALTER TABLE brainstorm_idea ENABLE TRIGGER ALL;")
示例#58
0
 def forwards(self, orm):
     db.delete_foreign_key('sentry_message', 'group_id')
     db.delete_foreign_key('sentry_message', 'project_id')
     db.delete_foreign_key('sentry_eventmapping', 'group_id')
     db.delete_foreign_key('sentry_eventmapping', 'project_id')