Update tables structure

This commit is contained in:
littlewolf 2019-10-07 22:23:01 +03:00
parent 4e96d09513
commit ab768311f0
3 changed files with 88 additions and 51 deletions

View File

@ -1,4 +1,37 @@
"""
Структура записи в card:
Название таблицы в postgresql: {
"data_type": "тип данных в таблице (словарь, объект, дочерний объект и так далее)",
"dependencies": кортеж с зависимостями от других таблиц в postgresql,
"fields": список полей для таблицы postgresql, пример:
{
"название legacy таблицы": {
список полей для переноса, пример структуры описан далее
},
"relations": список зависимостей legacy-таблицы, пример:
{
"название legacy таблицы": {
"key": ключ для связи. Строка, если тип поля в legacy таблице - ForeignKey, или кортеж из названия поля
в дочерней таблице и названия поля в родительской таблице в ином случае
"fields": {
список полей для переноса, пример структуры описан далее
}
}
}
},
"relations": список внешних ключей таблицы postgresql, пример структуры описан далее
{
"Cities": [(
(None, "region_code"),
("Region", "region", "code", "CharField")),
((None, "country_code_2"),
("Country", "country", "code", "CharField"))
]
}
},
Структура fields:
key - поле в таблице postgres
value - поле или группа полей в таблице legacy
@ -67,9 +100,14 @@ card = {
"postal_code": "zip_code",
"is_island": ("is_island", "Boolean")
},
"relations": {
"CityNames": {
"key": "city",
"fields": {
"name": "name",
},
}
}
}
},
"relations": {
"Cities": [(

View File

@ -567,49 +567,49 @@ class EmailAddresses(MigrateMixin):
db_table = 'email_addresses'
class Reviews(MigrateMixin):
using = 'legacy'
# class Reviews(MigrateMixin):
# using = 'legacy'
#
# vintage = models.PositiveIntegerField()
# mark = models.FloatField(blank=True, null=True)
# favorite = models.IntegerField(blank=True, null=True)
# account = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
# establishment = models.ForeignKey(Establishments, models.DO_NOTHING, blank=True, null=True)
# visited_at = models.DateField(blank=True, null=True)
# created_at = models.DateTimeField()
# published_at = models.DateTimeField(blank=True, null=True)
# updated_at = models.DateTimeField()
# aasm_state = models.CharField(max_length=255, blank=True, null=True)
# reviewer_id = models.IntegerField()
# priority = models.IntegerField(blank=True, null=True)
# #TODO: модель Products в postgres закомментирована
# product = models.ForeignKey("Products", models.DO_NOTHING, blank=True, null=True)
# received_at = models.DateTimeField(blank=True, null=True)
# reviewer_name = models.CharField(max_length=255, blank=True, null=True)
# type = models.CharField(max_length=255, blank=True, null=True)
# locked = models.IntegerField(blank=True, null=True)
# temporary = models.IntegerField(blank=True, null=True)
# last_state_change_at = models.DateTimeField(blank=True, null=True)
# editor = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
#
# class Meta:
# managed = False
# db_table = 'reviews'
#
vintage = models.PositiveIntegerField()
mark = models.FloatField(blank=True, null=True)
favorite = models.IntegerField(blank=True, null=True)
account = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
establishment = models.ForeignKey(Establishments, models.DO_NOTHING, blank=True, null=True)
visited_at = models.DateField(blank=True, null=True)
created_at = models.DateTimeField()
published_at = models.DateTimeField(blank=True, null=True)
updated_at = models.DateTimeField()
aasm_state = models.CharField(max_length=255, blank=True, null=True)
reviewer_id = models.IntegerField()
priority = models.IntegerField(blank=True, null=True)
#TODO: модель Products в postgres закомментирована
product = models.ForeignKey("Products", models.DO_NOTHING, blank=True, null=True)
received_at = models.DateTimeField(blank=True, null=True)
reviewer_name = models.CharField(max_length=255, blank=True, null=True)
type = models.CharField(max_length=255, blank=True, null=True)
locked = models.IntegerField(blank=True, null=True)
temporary = models.IntegerField(blank=True, null=True)
last_state_change_at = models.DateTimeField(blank=True, null=True)
editor = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
class Meta:
managed = False
db_table = 'reviews'
class ReviewTexts(MigrateMixin):
using = 'legacy'
review = models.ForeignKey('Reviews', models.DO_NOTHING, blank=True, null=True)
locale = models.CharField(max_length=5, blank=True, null=True)
text = models.TextField(blank=True, null=True)
updated_by = models.ForeignKey(Accounts, models.DO_NOTHING, db_column='updated_by', blank=True, null=True)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
class Meta:
managed = False
db_table = 'review_texts'
# class ReviewTexts(MigrateMixin):
# using = 'legacy'
#
# review = models.ForeignKey('Reviews', models.DO_NOTHING, blank=True, null=True)
# locale = models.CharField(max_length=5, blank=True, null=True)
# text = models.TextField(blank=True, null=True)
# updated_by = models.ForeignKey(Accounts, models.DO_NOTHING, db_column='updated_by', blank=True, null=True)
# created_at = models.DateTimeField()
# updated_at = models.DateTimeField()
#
# class Meta:
# managed = False
# db_table = 'review_texts'
class Comments(MigrateMixin):
using = 'legacy'

View File

@ -63,6 +63,8 @@ def transfer_model(model, card):
print(f"ERROR: model {model} from {card['app_label']} can not be loaded: {e}")
return
querysets = {}
for legacy_table, fields in card['fields'].items():
try:
legacy_model = apps.get_model(app_label="transfer", model_name=legacy_table)
@ -70,11 +72,8 @@ def transfer_model(model, card):
print(f"ERROR: legacy model {model} can not be loaded: {e}")
return
print(app_model)
print(legacy_model)
print(fields)
print(f"APP MODEL: {app_model}")
print(f"LEGACY MODEL: {legacy_model}")
print(f"FIELDS: {fields}")