示例#1
0
    def test_drop_index(self):
        table = Table("users")
        table.add_index("name", "name_index", "unique")

        diff = TableDiff("users")
        diff.from_table = table
        diff.remove_index("name")

        sql = ["DROP INDEX name"]

        self.assertEqual(sql, self.platform.compile_alter_sql(diff))
示例#2
0
    def test_drop_index_and_rename_table(self):
        table = Table("users")
        table.add_index("name", "name_unique", "unique")

        diff = TableDiff("users")
        diff.from_table = table
        diff.new_name = "clients"
        diff.remove_index("name_unique")

        sql = ["DROP INDEX name_unique", "ALTER TABLE users RENAME TO clients"]

        self.assertEqual(sql, self.platform.compile_alter_sql(diff))
示例#3
0
    def test_alter_rename_column_and_rename_table_and_drop_index(self):
        table = Table("users")
        table.add_column("post", "integer")
        table.add_index("name", "name_unique", "unique")

        diff = TableDiff("users")
        diff.from_table = table
        diff.new_name = "clients"
        diff.rename_column("post", "comment", "integer")
        diff.remove_index("name")

        sql = [
            "DROP INDEX name",
            "CREATE TEMPORARY TABLE __temp__users AS SELECT post FROM users",
            'DROP TABLE "users"',
            'CREATE TABLE "users" ("comment" INTEGER NOT NULL)',
            'INSERT INTO "users" ("comment") SELECT post FROM __temp__users',
            "DROP TABLE __temp__users",
            'ALTER TABLE "users" RENAME TO "clients"',
        ]

        self.assertEqual(sql, self.platform.compile_alter_sql(diff))