Пример #1
0
 def backwards(self, orm):
     db.rename_column("cmsplugin_textpublic", "cmspluginpublic_ptr_id",
                      "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('text_text', 'public_id', orm['text.text:public'])
Пример #2
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'])
    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
 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")
Пример #5
0
 def forwards(self, orm):
     
     db.rename_table("file_file", "cmsplugin_file")
     db.rename_table("file_publicfile", "cmsplugin_filepublic")
     db.alter_column('cmsplugin_file', 'public_id', orm['file.file:public'])
     try:
         db.delete_foreign_key('cmsplugin_file' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_filepublic")
     db.rename_column("cmsplugin_filepublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.create_primary_key("cmsplugin_filepublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql('cmsplugin_file' ,'public_id', 'cmsplugin_filepublic', 'cmspluginpublic_ptr_id')
Пример #6
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')
Пример #7
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')
Пример #8
0
 def forwards(self, orm):
     
     db.rename_table("googlemap_googlemap", "cmsplugin_googlemap")
     db.rename_table("googlemap_publicgooglemap", "cmsplugin_googlemappublic")
     db.rename_column("cmsplugin_googlemappublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.alter_column('cmsplugin_googlemap', 'public_id', orm['googlemap.googlemap:public'])
     try:
         db.delete_foreign_key('cmsplugin_googlemap' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_googlemappublic")
     db.create_primary_key("cmsplugin_googlemappublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql('cmsplugin_googlemap' ,'public_id', 'cmsplugin_googlemappublic', 'cmspluginpublic_ptr_id')
Пример #9
0
 def forwards(self, orm):
     
     db.rename_table("googlemap_googlemap", "cmsplugin_googlemap")
     db.rename_table("googlemap_publicgooglemap", "cmsplugin_googlemappublic")
     db.alter_column('cmsplugin_googlemap', 'public_id', orm['googlemap.googlemap:public'])
     try:
         db.delete_foreign_key('cmsplugin_googlemap' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_googlemappublic")
     db.rename_column("cmsplugin_googlemappublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.create_primary_key("cmsplugin_googlemappublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql('cmsplugin_googlemap' ,'public_id', 'cmsplugin_googlemappublic', 'cmspluginpublic_ptr_id')
Пример #10
0
 def forwards(self, orm):
     
     db.rename_table("flash_flash", "cmsplugin_flash")
     db.rename_table("flash_publicflash", "cmsplugin_flashpublic")
     db.alter_column('cmsplugin_flash', 'public_id', orm['flash.flash:public'])
     try:
         db.delete_foreign_key('cmsplugin_flash' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_flashpublic")
     db.rename_column("cmsplugin_flashpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.create_primary_key("cmsplugin_flashpublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql('cmsplugin_flash' ,'public_id', 'cmsplugin_flashpublic', 'cmspluginpublic_ptr_id')
Пример #11
0
 def forwards(self, orm):
     
     db.rename_table("link_link", "cmsplugin_link")
     db.rename_table("link_publiclink", "cmsplugin_linkpublic")
     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.rename_column("cmsplugin_linkpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.create_primary_key("cmsplugin_linkpublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql('cmsplugin_link' ,'public_id', 'cmsplugin_linkpublic', 'cmspluginpublic_ptr_id')
Пример #12
0
 def forwards(self, orm):
     
     db.rename_table("snippet_snippetptr", "cmsplugin_snippetptr")
     db.rename_table("snippet_publicsnippetptr", "cmsplugin_snippetptrpublic")
     db.alter_column('cmsplugin_snippetptr', 'public_id', orm['snippet.snippetptr:public'])
     try:
         db.delete_foreign_key('cmsplugin_snippetptr' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_snippetptrpublic")
     db.rename_column("cmsplugin_snippetptrpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.create_primary_key("cmsplugin_snippetptrpublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql('cmsplugin_snippetptr' ,'public_id', 'cmsplugin_snippetptrpublic', 'cmspluginpublic_ptr_id')
 def backwards(self, orm):
     db.delete_primary_key("ralph_assets_assetcategory")
     db.add_column('ralph_assets_assetcategory', 'parent_new_id',
                   self.gf('django.db.models.fields.IntegerField')(blank=True,
                   null=True, db_index=False))
     db.add_column('ralph_assets_assetcategory', 'id',
                   self.gf('django.db.models.fields.AutoField')(blank=True,
                   null=False, db_index=False, primary_key=True, max_length=10))
     db.add_column('ralph_assets_asset', 'category_new_id',
                   self.gf('django.db.models.fields.IntegerField')(blank=True,
                   null=True, db_index=False))
     db.add_column('ralph_assets_assetmodel', 'category_new_id',
                   self.gf('django.db.models.fields.IntegerField')(blank=True,
                   null=True, db_index=False))
     db.start_transaction()
     for i, slug in enumerate(
         db.execute('SELECT slug FROM ralph_assets_assetcategory')):
         slug = slug[0]
         db.execute("UPDATE ralph_assets_assetcategory SET id = %s "
                    "WHERE slug = %s",
                     [i+1, slug])
         db.execute("UPDATE ralph_assets_assetcategory SET parent_new_id = %s "
                    "WHERE parent_id = %s",
                     [i+1, slug])
         db.execute("UPDATE ralph_assets_asset SET category_new_id = %s "
                    "WHERE category_id = %s",
                     [i+1, slug])
         db.execute("UPDATE ralph_assets_assetmodel SET category_new_id = %s "
                    "WHERE category_id = %s",
                     [i+1, slug])
     db.commit_transaction()
     db.delete_column('ralph_assets_assetcategory', 'slug')
     db.delete_column('ralph_assets_assetcategory', 'parent_id')
     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')
     sql = db.foreign_key_sql('ralph_assets_asset',
         'category_id', 'ralph_assets_assetcategory', 'id')
     db.execute(sql)
     sql = db.foreign_key_sql('ralph_assets_assetmodel',
         'category_id', 'ralph_assets_assetcategory', 'id')
     db.execute(sql)
     sql = db.foreign_key_sql('ralph_assets_assetcategory',
         'parent_id', 'ralph_assets_assetcategory', 'id')
     db.execute(sql)
     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)
 def forwards(self, orm):        
     # Adding field 'Postrevision'
     db.add_column('askbot_postrevision', 'category_id',
                   self.gf('django.db.models.fields.IntegerField')(null=False),
                   keep_default=False)
     sql = db.foreign_key_sql('askbot_postrevision', 'category_id', 'category', 'id')           
     db.execute(sql)
     
     # Adding field 'draftquestion'        
     db.add_column('askbot_draftquestion', 'category_id',
                   self.gf('django.db.models.fields.IntegerField')(null=False),
                   keep_default=False)
     sql = db.foreign_key_sql('askbot_draftquestion', 'category_id', 'category', 'id')           
     db.execute(sql)  
Пример #15
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'])
Пример #16
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')
    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 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))
 def forwards(self, orm):
     
     # Create table 'category'
     db.add_column('askbot_thread', 'category_id',
                   self.gf('django.db.models.fields.IntegerField')(null=False),
                   keep_default=False)
     sql = db.foreign_key_sql('askbot_thread', 'category_id', 'category', '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)
    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)
Пример #22
0
    def forwards(self, orm):

        db.rename_table("snippet_snippetptr", "cmsplugin_snippetptr")
        db.rename_table("snippet_publicsnippetptr",
                        "cmsplugin_snippetptrpublic")
        db.rename_column("cmsplugin_snippetptrpublic",
                         "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
        db.alter_column('cmsplugin_snippetptr', 'public_id',
                        orm['snippet.snippetptr:public'])
        try:
            db.delete_foreign_key('cmsplugin_snippetptr', 'public_id')
        except:
            pass
        db.drop_primary_key("cmsplugin_snippetptrpublic")
        db.create_primary_key("cmsplugin_snippetptrpublic",
                              ("cmspluginpublic_ptr_id", ))
        db.foreign_key_sql('cmsplugin_snippetptr', 'public_id',
                           'cmsplugin_snippetptrpublic',
                           'cmspluginpublic_ptr_id')
Пример #23
0
 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))
    def forwards(self, orm):

        # Create table 'category'
        db.add_column(
            'askbot_anonymousquestion',
            'category_id',
            self.gf('django.db.models.fields.IntegerField')(null=False),
            keep_default=False)
        sql = db.foreign_key_sql('askbot_anonymousquestion', 'category_id',
                                 'category', 'id')
        db.execute(sql)
    def forwards(self, orm):
        ContentType = orm['contenttypes.ContentType']

        ct1 = ContentType.objects.get(
            app_label='libretto', model='caracteristiquedelementdeprogramme')
        ct1.model = 'caracteristiquedeprogramme'
        ct1.name = 'caractéristique de programme'
        ct1.save()

        ct2 = ContentType.objects.get(
            app_label='libretto',
            model='typedeparentedoeuvres')
        ct2.name = 'type de parenté d’œuvres'
        ct2.save()

        ct3 = ContentType.objects.get(
            app_label='libretto',
            model='typedeparentedindividus')
        ct3.name = 'type de parenté d’individus'
        ct3.save()

        db.rename_column('libretto_elementdeprogramme_caracteristiques',
                         'caracteristiquedelementdeprogramme_id',
                         'caracteristiquedeprogramme_id')

        sql = db.foreign_key_sql(
            'libretto_elementdeprogramme_caracteristiques',
            'caracteristiquedeprogramme_id',
            'libretto_caracteristiquedeprogramme',
            'caracteristique_ptr_id')
        db.execute(sql)

        sql = db.foreign_key_sql(
            'libretto_oeuvre_caracteristiques',
            'caracteristiquedoeuvre_id',
            'libretto_caracteristiquedoeuvre',
            'caracteristique_ptr_id')
        db.execute(sql)
    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;")
    def forwards(self, orm):
        #import pdb; pdb.set_trace()
        # Use auth_user as a proxy for all tables existing
        if db_table_exists('auth_user'):
            # Presumably migrating from Django < 1.5
            db.rename_table('auth_user', 'tao_taouser')
            db.rename_table('auth_user_user_permissions', 'tao_taouser_user_permissions')
            db.rename_table('auth_user_groups', 'tao_taouser_groups')
            db.rename_column('tao_taouser_groups','user_id','taouser_id')
            db.rename_column('tao_taouser_user_permissions','user_id','taouser_id')
            db.execute( db.foreign_key_sql('tao_job','user_id','tao_taouser','id') )
        else:
            # Presumably clean install with Django >= 1.5
            db.create_table('tao_taouser', (
                ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
                ('password', self.gf('django.db.models.fields.CharField')(max_length=128)),
                ('last_login', self.gf('django.db.models.fields.DateTimeField')()),
                ('is_superuser', self.gf('django.db.models.fields.BooleanField')(default=False)),
                ('username', self.gf('django.db.models.fields.CharField')(max_length=30)),
                ('first_name', self.gf('django.db.models.fields.CharField')(max_length=30)),
                ('last_name', self.gf('django.db.models.fields.CharField')(max_length=30)),
                ('email', self.gf('django.db.models.fields.CharField')(max_length=75)),
                ('is_staff', self.gf('django.db.models.fields.BooleanField')(default=False)),
                ('is_active', self.gf('django.db.models.fields.BooleanField')(default=False)),
                ('date_joined', self.gf('django.db.models.fields.DateTimeField')()),
                ))
            db.create_unique('tao_taouser', ['username'])

            db.create_table('tao_taouser_user_permissions', (
                ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
                ('taouser_id', self.gf('django.db.models.fields.IntegerField')()),
                ('permission', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.Permission']))
                ))
            db.create_index('tao_taouser_user_permissions', ['taouser_id'])
            db.create_index('tao_taouser_user_permissions', ['permission_id'])
            db.create_unique('tao_taouser_user_permissions', ['taouser_id', 'permission_id'])

            db.create_table('tao_taouser_groups', (
                ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
                ('taouser_id', self.gf('django.db.models.fields.IntegerField')()),
                ('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.Group']))
                ))
            db.create_index('tao_taouser_groups', ['taouser_id'])
            db.create_index('tao_taouser_groups', ['group_id'])
        db.send_create_signal('tao', ['TaoUser'])
Пример #28
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'])
Пример #29
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)
Пример #30
0
 def backwards(self, orm): 
     db.rename_column("cmsplugin_textpublic", "cmspluginpublic_ptr_id", "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('text_text', 'public_id', orm['text.text:public'])
Пример #31
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;")
Пример #32
0
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)