diff --git a/bin/player-account-step1.patch b/bin/player-account-step1.patch new file mode 100644 index 0000000000..c13e8e9d25 --- /dev/null +++ b/bin/player-account-step1.patch @@ -0,0 +1,223 @@ +diff --git a/evennia/comms/migrations/0015_auto_20170706_2041.py b/evennia/comms/migrations/0015_auto_20170706_2041.py +index ec5fc29..62b7936 100644 +--- a/evennia/comms/migrations/0015_auto_20170706_2041.py ++++ b/evennia/comms/migrations/0015_auto_20170706_2041.py +@@ -2,7 +2,12 @@ + # Generated by Django 1.11.2 on 2017-07-06 20:41 + from __future__ import unicode_literals + +-from django.db import migrations ++from django.db import migrations, connection ++ ++ ++def _table_exists(db_cursor, tablename): ++ "Returns bool if table exists or not" ++ return tablename in connection.introspection.table_names() + + + class Migration(migrations.Migration): +@@ -11,17 +16,23 @@ class Migration(migrations.Migration): + ('comms', '0014_auto_20170705_1736'), + ] + +- operations = [ +- migrations.RemoveField( +- model_name='channeldb', +- name='db_subscriptions', +- ), +- migrations.RemoveField( +- model_name='msg', +- name='db_receivers_players', +- ), +- migrations.RemoveField( +- model_name='msg', +- name='db_sender_players', +- ), +- ] ++ db_cursor = connection.cursor() ++ ++ if not _table_exists(db_cursor, "channels.channeldb_db_receivers_players"): ++ # OBS - this is run BEFORE migrations are run! ++ operations = [] ++ else: ++ operations = [ ++ migrations.RemoveField( ++ model_name='channeldb', ++ name='db_subscriptions', # this is now db_account_subscriptions ++ ), ++ migrations.RemoveField( ++ model_name='msg', ++ name='db_receivers_players', ++ ), ++ migrations.RemoveField( ++ model_name='msg', ++ name='db_sender_players', ++ ), ++ ] +diff --git a/evennia/objects/migrations/0007_objectdb_db_account.py b/evennia/objects/migrations/0007_objectdb_db_account.py +index b27c75c..6e40252 100644 +--- a/evennia/objects/migrations/0007_objectdb_db_account.py ++++ b/evennia/objects/migrations/0007_objectdb_db_account.py +@@ -2,21 +2,31 @@ + # Generated by Django 1.11.2 on 2017-07-05 17:27 + from __future__ import unicode_literals + +-from django.db import migrations, models ++from django.db import migrations, models, connection + 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): + + dependencies = [ + ('accounts', '0002_copy_player_to_account'), + ('objects', '0006_auto_20170606_1731'), + ] + +- operations = [ +- migrations.AddField( +- model_name='objectdb', +- name='db_account', +- field=models.ForeignKey(help_text=b'an Account connected to this object, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.AccountDB', verbose_name=b'account'), +- ), +- ] ++ 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 = [ ++ migrations.AddField( ++ model_name='objectdb', ++ name='db_account', ++ field=models.ForeignKey(help_text=b'an Account connected to this object, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.AccountDB', verbose_name=b'account'), ++ ), ++ ] +diff --git a/evennia/objects/migrations/0009_remove_objectdb_db_player.py b/evennia/objects/migrations/0009_remove_objectdb_db_player.py +index 80161a1..10fb225 100644 +--- a/evennia/objects/migrations/0009_remove_objectdb_db_player.py ++++ b/evennia/objects/migrations/0009_remove_objectdb_db_player.py +@@ -2,7 +2,12 @@ + # Generated by Django 1.11.2 on 2017-07-06 20:41 + from __future__ import unicode_literals + +-from django.db import migrations ++from django.db import migrations, connection ++ ++ ++def _table_exists(db_cursor, tablename): ++ "Returns bool if table exists or not" ++ return tablename in connection.introspection.table_names() + + + class Migration(migrations.Migration): +@@ -11,9 +16,15 @@ class Migration(migrations.Migration): + ('objects', '0008_auto_20170705_1736'), + ] + +- operations = [ +- migrations.RemoveField( +- model_name='objectdb', +- name='db_player', +- ), +- ] ++ db_cursor = connection.cursor() ++ ++ if not _table_exists(db_cursor, "objectdb_db_player"): ++ # OBS - this is run BEFORE migrations are run! ++ operations = [] ++ else: ++ operations = [ ++ migrations.RemoveField( ++ model_name='objectdb', ++ name='db_player', ++ ), ++ ] +diff --git a/evennia/scripts/migrations/0009_scriptdb_db_account.py b/evennia/scripts/migrations/0009_scriptdb_db_account.py +index 99baf70..23f6df9 100644 +--- a/evennia/scripts/migrations/0009_scriptdb_db_account.py ++++ b/evennia/scripts/migrations/0009_scriptdb_db_account.py +@@ -2,21 +2,31 @@ + # Generated by Django 1.11.2 on 2017-07-05 17:27 + from __future__ import unicode_literals + +-from django.db import migrations, models ++from django.db import migrations, models, connection + 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): + + dependencies = [ + ('accounts', '0002_copy_player_to_account'), + ('scripts', '0008_auto_20170606_1731'), + ] + +- operations = [ +- migrations.AddField( +- model_name='scriptdb', +- name='db_account', +- field=models.ForeignKey(blank=True, help_text=b'the account to store this script on (should not be set if db_obj is set)', null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.AccountDB', verbose_name=b'scripted account'), +- ), +- ] ++ 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 = [ ++ migrations.AddField( ++ model_name='scriptdb', ++ name='db_account', ++ field=models.ForeignKey(blank=True, help_text=b'the account to store this script on (should not be set if db_obj is set)', null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.AccountDB', verbose_name=b'scripted account'), ++ ), ++ ] +diff --git a/evennia/scripts/migrations/0011_remove_scriptdb_db_player.py b/evennia/scripts/migrations/0011_remove_scriptdb_db_player.py +index d3746a5..20fa63f 100644 +--- a/evennia/scripts/migrations/0011_remove_scriptdb_db_player.py ++++ b/evennia/scripts/migrations/0011_remove_scriptdb_db_player.py +@@ -2,7 +2,12 @@ + # Generated by Django 1.11.2 on 2017-07-06 20:41 + from __future__ import unicode_literals + +-from django.db import migrations ++from django.db import migrations, connection ++ ++ ++def _table_exists(db_cursor, tablename): ++ "Returns bool if table exists or not" ++ return tablename in connection.introspection.table_names() + + + class Migration(migrations.Migration): +@@ -11,9 +16,14 @@ class Migration(migrations.Migration): + ('scripts', '0010_auto_20170705_1736'), + ] + +- operations = [ +- migrations.RemoveField( +- model_name='scriptdb', +- name='db_player', +- ), +- ] ++ db_cursor = connection.cursor() ++ ++ if not _table_exists(db_cursor, 'scripts_scriptdb_db_player'): ++ operations = [] ++ else: ++ operations = [ ++ migrations.RemoveField( ++ model_name='scriptdb', ++ name='db_player', ++ ), ++ ]