Create parallel Player/Account fields and copy all

This commit is contained in:
Griatch 2017-07-06 22:29:52 +02:00
parent ee0e9cc053
commit 63c96de443
10 changed files with 226 additions and 2 deletions

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-07-05 17:27
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
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'),
),
]

View file

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-07-05 17:36
from __future__ import unicode_literals
from django.db import migrations
def forwards(apps, schema_editor):
try:
apps.get_model('players', 'PlayerDB')
except LookupError:
return
AccountDB = apps.get_model('accounts', 'AccountDB')
ObjectDB = apps.get_model('objects', 'ObjectDB')
for object in ObjectDB.objects.all():
player = object.db_player
if player:
account = AccountDB.objects.get(id=player.id)
object.db_account = account
object.save(update_fields=['db_account'])
class Migration(migrations.Migration):
dependencies = [
('objects', '0007_objectdb_db_account'),
]
operations = [
migrations.RunPython(forwards)
]

View file

@ -170,8 +170,12 @@ class ObjectDB(TypedObject):
# will automatically save and cache the data more efficiently.
# If this is a character object, the player is connected here.
# TODO Player-Account
db_player = models.ForeignKey("players.PlayerDB", null=True, verbose_name='player', on_delete=models.SET_NULL,
help_text='a Player connected to this object, if any.')
db_account = models.ForeignKey("accounts.AccountDB", null=True, verbose_name='account', on_delete=models.SET_NULL,
help_text='an Account connected to this object, if any.')
# the session id associated with this player, if any
db_sessid = models.CharField(null=True, max_length=32, validators=[validate_comma_separated_integer_list],
verbose_name="session id",