Fix migration edge cases with MySQL and PostgreSQL
This commit is contained in:
parent
fb773a9e75
commit
414bacf58b
7 changed files with 44 additions and 51 deletions
|
|
@ -3,17 +3,11 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models, connection
|
from django.db import migrations, models, connection
|
||||||
from django.db import OperationalError
|
|
||||||
|
|
||||||
|
|
||||||
def _table_exists(db_cursor, tablename):
|
def _table_exists(db_cursor, tablename):
|
||||||
"Returns bool if table exists or not"
|
"Returns bool if table exists or not"
|
||||||
sql_check_exists = "SELECT * from %s;" % tablename
|
return tablename in connection.introspection.table_names()
|
||||||
try:
|
|
||||||
db_cursor.execute(sql_check_exists)
|
|
||||||
return True
|
|
||||||
except OperationalError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,12 @@
|
||||||
# Generated by Django 1.11.2 on 2017-07-06 20:41
|
# Generated by Django 1.11.2 on 2017-07-06 20:41
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, OperationalError, connection
|
from django.db import migrations, connection
|
||||||
|
|
||||||
|
|
||||||
def _table_exists(db_cursor, tablename):
|
def _table_exists(db_cursor, tablename):
|
||||||
"Returns bool if table exists or not"
|
"Returns bool if table exists or not"
|
||||||
sql_check_exists = "SELECT * from %s;" % tablename
|
return tablename in connection.introspection.table_names()
|
||||||
try:
|
|
||||||
db_cursor.execute(sql_check_exists)
|
|
||||||
return True
|
|
||||||
except OperationalError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,15 @@
|
||||||
# Generated by Django 1.11.2 on 2017-07-05 17:27
|
# Generated by Django 1.11.2 on 2017-07-05 17:27
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models, connection
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
def _table_exists(db_cursor, tablename):
|
||||||
|
"Returns bool if table exists or not"
|
||||||
|
return tablename in connection.introspection.table_names()
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|
@ -13,6 +18,11 @@ class Migration(migrations.Migration):
|
||||||
('objects', '0006_auto_20170606_1731'),
|
('objects', '0006_auto_20170606_1731'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
db_cursor = connection.cursor()
|
||||||
|
operations = []
|
||||||
|
if _table_exists(db_cursor, "players_playerdb"):
|
||||||
|
# OBS - this is run BEFORE migrations even start, so if we have a player table
|
||||||
|
# here we are not starting from scratch.
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='objectdb',
|
model_name='objectdb',
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, connection
|
from django.db import migrations, connection
|
||||||
from django.db import OperationalError
|
|
||||||
|
|
||||||
|
|
||||||
def _table_exists(db_cursor, tablename):
|
def _table_exists(db_cursor, tablename):
|
||||||
"Returns bool if table exists or not"
|
"Returns bool if table exists or not"
|
||||||
sql_check_exists = "SELECT * from %s;" % tablename
|
return tablename in connection.introspection.table_names()
|
||||||
try:
|
|
||||||
db_cursor.execute(sql_check_exists)
|
|
||||||
return True
|
|
||||||
except OperationalError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,15 @@
|
||||||
# Generated by Django 1.11.2 on 2017-07-05 17:27
|
# Generated by Django 1.11.2 on 2017-07-05 17:27
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models, connection
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
def _table_exists(db_cursor, tablename):
|
||||||
|
"Returns bool if table exists or not"
|
||||||
|
return tablename in connection.introspection.table_names()
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|
@ -13,6 +18,11 @@ class Migration(migrations.Migration):
|
||||||
('scripts', '0008_auto_20170606_1731'),
|
('scripts', '0008_auto_20170606_1731'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
db_cursor = connection.cursor()
|
||||||
|
operations = []
|
||||||
|
if _table_exists(db_cursor, "players_playerdb"):
|
||||||
|
# OBS - this is run BEFORE migrations even start, so if we have a player table
|
||||||
|
# here we are not starting from scratch.
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='scriptdb',
|
model_name='scriptdb',
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,12 @@
|
||||||
# Generated by Django 1.11.2 on 2017-07-06 20:41
|
# Generated by Django 1.11.2 on 2017-07-06 20:41
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, OperationalError, connection
|
from django.db import migrations, connection
|
||||||
|
|
||||||
|
|
||||||
def _table_exists(db_cursor, tablename):
|
def _table_exists(db_cursor, tablename):
|
||||||
"Returns bool if table exists or not"
|
"Returns bool if table exists or not"
|
||||||
sql_check_exists = "SELECT * from %s;" % tablename
|
return tablename in connection.introspection.table_names()
|
||||||
try:
|
|
||||||
db_cursor.execute(sql_check_exists)
|
|
||||||
return True
|
|
||||||
except OperationalError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,12 @@
|
||||||
# Generated by Django 1.11.3 on 2017-07-13 18:47
|
# Generated by Django 1.11.3 on 2017-07-13 18:47
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, OperationalError, connection
|
from django.db import migrations, connection
|
||||||
|
|
||||||
|
|
||||||
def _table_exists(db_cursor, tablename):
|
def _table_exists(db_cursor, tablename):
|
||||||
"Returns bool if table exists or not"
|
"Returns bool if table exists or not"
|
||||||
sql_check_exists = "SELECT * from %s;" % tablename
|
return tablename in connection.introspection.table_names()
|
||||||
try:
|
|
||||||
db_cursor.execute(sql_check_exists)
|
|
||||||
return True
|
|
||||||
except OperationalError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _drop_table(db_cursor, table_name):
|
def _drop_table(db_cursor, table_name):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue