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: Структура fields:
key - поле в таблице postgres key - поле в таблице postgres
value - поле или группа полей в таблице legacy value - поле или группа полей в таблице legacy
@ -67,9 +100,14 @@ card = {
"postal_code": "zip_code", "postal_code": "zip_code",
"is_island": ("is_island", "Boolean") "is_island": ("is_island", "Boolean")
}, },
"CityNames": { "relations": {
"name": "name", "CityNames": {
}, "key": "city",
"fields": {
"name": "name",
}
}
}
}, },
"relations": { "relations": {
"Cities": [( "Cities": [(

View File

@ -567,49 +567,49 @@ class EmailAddresses(MigrateMixin):
db_table = 'email_addresses' db_table = 'email_addresses'
class Reviews(MigrateMixin): # class Reviews(MigrateMixin):
using = 'legacy' # 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() # class ReviewTexts(MigrateMixin):
mark = models.FloatField(blank=True, null=True) # using = 'legacy'
favorite = models.IntegerField(blank=True, null=True) #
account = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True) # review = models.ForeignKey('Reviews', models.DO_NOTHING, blank=True, null=True)
establishment = models.ForeignKey(Establishments, models.DO_NOTHING, blank=True, null=True) # locale = models.CharField(max_length=5, blank=True, null=True)
visited_at = models.DateField(blank=True, null=True) # text = models.TextField(blank=True, null=True)
created_at = models.DateTimeField() # updated_by = models.ForeignKey(Accounts, models.DO_NOTHING, db_column='updated_by', blank=True, null=True)
published_at = models.DateTimeField(blank=True, null=True) # created_at = models.DateTimeField()
updated_at = models.DateTimeField() # updated_at = models.DateTimeField()
aasm_state = models.CharField(max_length=255, blank=True, null=True) #
reviewer_id = models.IntegerField() # class Meta:
priority = models.IntegerField(blank=True, null=True) # managed = False
#TODO: модель Products в postgres закомментирована # db_table = 'review_texts'
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 Comments(MigrateMixin): class Comments(MigrateMixin):
using = 'legacy' 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}") print(f"ERROR: model {model} from {card['app_label']} can not be loaded: {e}")
return return
querysets = {}
for legacy_table, fields in card['fields'].items(): for legacy_table, fields in card['fields'].items():
try: try:
legacy_model = apps.get_model(app_label="transfer", model_name=legacy_table) 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}") print(f"ERROR: legacy model {model} can not be loaded: {e}")
return return
print(app_model) print(f"APP MODEL: {app_model}")
print(legacy_model)
print(fields)
print(f"LEGACY MODEL: {legacy_model}")
print(f"FIELDS: {fields}")