mirror of
https://github.com/evennia/evennia.git
synced 2026-03-31 21:17:17 +02:00
Correct migrations to not re-remove fields.
This commit is contained in:
parent
c1326eaf23
commit
594500c4c7
5 changed files with 123 additions and 54 deletions
|
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||
from django.db import migrations, models, connection
|
||||
from django.db import OperationalError
|
||||
|
||||
|
||||
def _table_exists(db_cursor, tablename):
|
||||
"Returns bool if table exists or not"
|
||||
sql_check_exists = "SELECT * from %s;" % tablename
|
||||
|
|
@ -24,12 +25,48 @@ class Migration(migrations.Migration):
|
|||
|
||||
db_cursor = connection.cursor()
|
||||
|
||||
if not _table_exists(db_cursor, 'comms_msg_db_hide_from_players'):
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='channeldb',
|
||||
name='db_account_subscriptions',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='account_subscription_set', to='accounts.AccountDB', verbose_name=b'account subscriptions'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='channeldb',
|
||||
name='db_object_subscriptions',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='object_subscription_set', to='objects.ObjectDB', verbose_name=b'object subscriptions'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='msg',
|
||||
name='db_receivers_scripts',
|
||||
field=models.ManyToManyField(blank=True, help_text=b'script_receivers', related_name='receiver_script_set', to='scripts.ScriptDB'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='msg',
|
||||
name='db_sender_scripts',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_script_set', to='scripts.ScriptDB', verbose_name=b'sender(script)'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='channeldb',
|
||||
name='db_object_subscriptions',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='object_subscription_set', to='objects.ObjectDB', verbose_name=b'object subscriptions'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='msg',
|
||||
name='db_receivers_scripts',
|
||||
field=models.ManyToManyField(blank=True, help_text=b'script_receivers', related_name='receiver_script_set', to='scripts.ScriptDB'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='msg',
|
||||
name='db_sender_scripts',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_script_set', to='scripts.ScriptDB', verbose_name=b'sender(script)'),
|
||||
),
|
||||
]
|
||||
|
||||
if _table_exists(db_cursor, 'comms_msg_db_hide_from_players'):
|
||||
# OBS - this is run BEFORE migrations are run!
|
||||
# not a migration of an existing database
|
||||
operations = []
|
||||
else:
|
||||
operations = [
|
||||
operations += [
|
||||
migrations.AddField(
|
||||
model_name='channeldb',
|
||||
name='db_account_subscriptions',
|
||||
|
|
@ -50,19 +87,4 @@ class Migration(migrations.Migration):
|
|||
name='db_sender_accounts',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_account_set', to='accounts.AccountDB', verbose_name=b'sender(account)'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='channeldb',
|
||||
name='db_object_subscriptions',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='object_subscription_set', to='objects.ObjectDB', verbose_name=b'object subscriptions'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='msg',
|
||||
name='db_receivers_scripts',
|
||||
field=models.ManyToManyField(blank=True, help_text=b'script_receivers', related_name='receiver_script_set', to='scripts.ScriptDB'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='msg',
|
||||
name='db_sender_scripts',
|
||||
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_script_set', to='scripts.ScriptDB', verbose_name=b'sender(script)'),
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,17 @@
|
|||
# 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, OperationalError, connection
|
||||
|
||||
|
||||
def _table_exists(db_cursor, tablename):
|
||||
"Returns bool if table exists or not"
|
||||
sql_check_exists = "SELECT * from %s;" % tablename
|
||||
try:
|
||||
db_cursor.execute(sql_check_exists)
|
||||
return True
|
||||
except OperationalError:
|
||||
return False
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
|
@ -11,17 +21,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_accounts',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='msg',
|
||||
name='db_sender_accounts',
|
||||
),
|
||||
]
|
||||
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',
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -483,7 +483,7 @@ class SubscriptionHandler(object):
|
|||
self._cache = None
|
||||
|
||||
def _recache(self):
|
||||
self._cache = {account : True for account in self.obj.db_subscriptions.all()}
|
||||
self._cache = {account : True for account in self.obj.db_account_subscriptions.all()}
|
||||
self._cache.update({obj : True for obj in self.obj.db_object_subscriptions.all()})
|
||||
|
||||
def has(self, entity):
|
||||
|
|
@ -528,7 +528,7 @@ class SubscriptionHandler(object):
|
|||
if clsname == "ObjectDB":
|
||||
self.obj.db_object_subscriptions.add(subscriber)
|
||||
elif clsname == "AccountDB":
|
||||
self.obj.db_subscriptions.add(subscriber)
|
||||
self.obj.db_account_subscriptions.add(subscriber)
|
||||
_CHANNELHANDLER.cached_cmdsets.pop(subscriber, None)
|
||||
self._recache()
|
||||
|
||||
|
|
@ -549,7 +549,7 @@ class SubscriptionHandler(object):
|
|||
clsname = subscriber.__dbclass__.__name__
|
||||
# chooses the right type
|
||||
if clsname == "AccountDB":
|
||||
self.obj.db_subscriptions.remove(entity)
|
||||
self.obj.db_account_subscriptions.remove(entity)
|
||||
elif clsname == "ObjectDB":
|
||||
self.obj.db_object_subscriptions.remove(entity)
|
||||
_CHANNELHANDLER.cached_cmdsets.pop(subscriber, None)
|
||||
|
|
@ -591,7 +591,7 @@ class SubscriptionHandler(object):
|
|||
Remove all subscribers from channel.
|
||||
|
||||
"""
|
||||
self.obj.db_subscriptions.clear()
|
||||
self.obj.db_account_subscriptions.clear()
|
||||
self.obj.db_object_subscriptions.clear()
|
||||
self._cache = None
|
||||
|
||||
|
|
@ -604,8 +604,7 @@ class ChannelDB(TypedObject):
|
|||
The Channel class defines the following database fields
|
||||
beyond the ones inherited from TypedObject:
|
||||
|
||||
- db_subscriptions: The Account subscriptions (this is the most
|
||||
usual case, named this way for legacy.
|
||||
- db_account_subscriptions: The Account subscriptions.
|
||||
- db_object_subscriptions: The Object subscriptions.
|
||||
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2,7 +2,18 @@
|
|||
# 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
|
||||
from django.db import OperationalError
|
||||
|
||||
|
||||
def _table_exists(db_cursor, tablename):
|
||||
"Returns bool if table exists or not"
|
||||
sql_check_exists = "SELECT * from %s;" % tablename
|
||||
try:
|
||||
db_cursor.execute(sql_check_exists)
|
||||
return True
|
||||
except OperationalError:
|
||||
return False
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
|
@ -11,9 +22,15 @@ class Migration(migrations.Migration):
|
|||
('objects', '0008_auto_20170705_1736'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='objectdb',
|
||||
name='db_account',
|
||||
),
|
||||
]
|
||||
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',
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,17 @@
|
|||
# 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, OperationalError, connection
|
||||
|
||||
|
||||
def _table_exists(db_cursor, tablename):
|
||||
"Returns bool if table exists or not"
|
||||
sql_check_exists = "SELECT * from %s;" % tablename
|
||||
try:
|
||||
db_cursor.execute(sql_check_exists)
|
||||
return True
|
||||
except OperationalError:
|
||||
return False
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
|
@ -11,9 +21,14 @@ class Migration(migrations.Migration):
|
|||
('scripts', '0010_auto_20170705_1736'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='scriptdb',
|
||||
name='db_account',
|
||||
),
|
||||
]
|
||||
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',
|
||||
),
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue