-
-
Notifications
You must be signed in to change notification settings - Fork 684
/
player-account-step1.patch
218 lines (196 loc) · 7.7 KB
/
player-account-step1.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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 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 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='an Account connected to this object, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.AccountDB', verbose_name='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='an Account connected to this object, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.AccountDB', verbose_name='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 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 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='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='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='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='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 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',
+ ),
+ ]