diff --git a/web/migrations/versions/09d53fca90c7_.py b/web/migrations/versions/09d53fca90c7_.py index 3214754f1..b797b6183 100644 --- a/web/migrations/versions/09d53fca90c7_.py +++ b/web/migrations/versions/09d53fca90c7_.py @@ -47,7 +47,12 @@ def upgrade(): if version < 5: db.engine.execute('ALTER TABLE server ADD COLUMN role text(64)') if version < 6: - db.engine.execute("ALTER TABLE server RENAME TO server_old") + # To Save previous data, create temp table + + db.engine.execute("create table server_old as select * from server") + + db.engine.execute("DROP TABLE server") + db.engine.execute(""" CREATE TABLE server ( id INTEGER NOT NULL, @@ -161,7 +166,10 @@ def upgrade(): """) if version < 12: - db.engine.execute("ALTER TABLE server RENAME TO server_old") + db.engine.execute("create table server_old as select * from server") + + db.engine.execute("DROP TABLE server") + db.engine.execute(""" CREATE TABLE server ( id INTEGER NOT NULL, diff --git a/web/migrations/versions/35f29b1701bd_.py b/web/migrations/versions/35f29b1701bd_.py index 653718e20..0599a3434 100644 --- a/web/migrations/versions/35f29b1701bd_.py +++ b/web/migrations/versions/35f29b1701bd_.py @@ -49,12 +49,6 @@ def upgrade(): db.engine.execute("DROP TABLE user_old") - # db.engine.execute("PRAGMA foreign_keys=ON") - - # db.session.commit() - - # db.engine.execute("PRAGMA foreign_keys=ON") - def downgrade(): # pgAdmin only upgrades, downgrade not implemented. diff --git a/web/migrations/versions/3ce25f562f3b_.py b/web/migrations/versions/3ce25f562f3b_.py index bf4f266d8..e47651041 100644 --- a/web/migrations/versions/3ce25f562f3b_.py +++ b/web/migrations/versions/3ce25f562f3b_.py @@ -24,12 +24,19 @@ depends_on = None def upgrade(): - db.engine.execute("create table user_old as select * from user") + # Rename user table to user_old and again user_old to user to change + # the foreign key refernce of user_old table which is not exists - db.engine.execute("DROP TABLE user") + db.engine.execute("ALTER TABLE user RENAME TO user_old") db.engine.execute("ALTER TABLE user_old RENAME TO user") + # Rename server table to server_old and again server_old to server to change + # the foreign key refernce of server_old table which is not exists + db.engine.execute("ALTER TABLE server RENAME TO server_old") + + db.engine.execute("ALTER TABLE server_old RENAME TO server") + def downgrade(): # pgAdmin only upgrades, downgrade not implemented. diff --git a/web/migrations/versions/50aad68f99c2_.py b/web/migrations/versions/50aad68f99c2_.py index cadd2e445..a308dc34f 100644 --- a/web/migrations/versions/50aad68f99c2_.py +++ b/web/migrations/versions/50aad68f99c2_.py @@ -17,8 +17,11 @@ depends_on = None def upgrade(): - # To Save previous data - db.engine.execute("ALTER TABLE server RENAME TO server_old") + # To Save previous data, create temp table + + db.engine.execute("create table server_old as select * from server") + + db.engine.execute("DROP TABLE server") # With service file some fields won't be mandatory as user can provide # them using service file. Removed NOT NULL constraint from few columns diff --git a/web/migrations/versions/7c56ea250085_.py b/web/migrations/versions/7c56ea250085_.py index 54a08588c..7d0b6f647 100644 --- a/web/migrations/versions/7c56ea250085_.py +++ b/web/migrations/versions/7c56ea250085_.py @@ -19,8 +19,11 @@ depends_on = None def upgrade(): - # To Save previous data - db.engine.execute("ALTER TABLE server RENAME TO server_old") + # To Save previous data, create temp table + + db.engine.execute("create table server_old as select * from server") + + db.engine.execute("DROP TABLE server") # Create table with new constraint definition db.engine.execute(""" diff --git a/web/migrations/versions/a39bd015b644_.py b/web/migrations/versions/a39bd015b644_.py index da887ab2d..a6f2796e1 100644 --- a/web/migrations/versions/a39bd015b644_.py +++ b/web/migrations/versions/a39bd015b644_.py @@ -17,8 +17,13 @@ depends_on = None def upgrade(): - # Rename older table to save previous data - db.engine.execute("ALTER TABLE sharedserver RENAME TO sharedserver_old") + + # To Save previous data, create temp table + + db.engine.execute("create table sharedserver_old as " + "select * from sharedserver") + + db.engine.execute("DROP TABLE sharedserver") # Create new table with removed not null constraints for port column. db.engine.execute(""" diff --git a/web/migrations/versions/a77a0932a568_.py b/web/migrations/versions/a77a0932a568_.py index 2702aa279..ff7fa392c 100644 --- a/web/migrations/versions/a77a0932a568_.py +++ b/web/migrations/versions/a77a0932a568_.py @@ -19,8 +19,10 @@ depends_on = None def upgrade(): - # To Save previous data - db.engine.execute("ALTER TABLE server RENAME TO server_old") + # To Save previous data, create temp table + db.engine.execute("create table server_old as select * from server") + + db.engine.execute("DROP TABLE server") # Create table with drop constraint for port and username definition db.engine.execute("""