Migrate user id to UUID
parent
682c42c0e8
commit
fb5521c9f7
@ -0,0 +1,47 @@
|
|||||||
|
# Generated by Django 4.1.7 on 2023-02-24 12:20
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0073_strategy_active_management_policy'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='session',
|
||||||
|
name='plan',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='session',
|
||||||
|
name='user',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='user',
|
||||||
|
old_name='stripe_id',
|
||||||
|
new_name='billing_provider_id',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='user',
|
||||||
|
name='last_payment',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='user',
|
||||||
|
name='plans',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='id',
|
||||||
|
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True),
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='Plan',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='Session',
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,50 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def fill_mymodel_uuid(apps, schema_editor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
MyModel = apps.get_model('core', 'User')
|
||||||
|
for obj in MyModel.objects.using(db_alias).all():
|
||||||
|
obj.uuid = uuid.uuid4()
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
""" Change model with integer pk to UUID pk. This migration presumes there
|
||||||
|
are no db constraints (foreign keys) to this table.
|
||||||
|
"""
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0074_remove_session_plan_remove_session_user_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='uuid',
|
||||||
|
field=models.UUIDField(null=True),
|
||||||
|
),
|
||||||
|
migrations.RunPython(fill_mymodel_uuid, migrations.RunPython.noop),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='uuid',
|
||||||
|
field=models.UUIDField(default=uuid.uuid4, serialize=False, editable=False, unique=True),
|
||||||
|
),
|
||||||
|
migrations.RemoveField('User', 'id'),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='user',
|
||||||
|
old_name='uuid',
|
||||||
|
new_name='id'
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='id',
|
||||||
|
field=models.UUIDField(primary_key=True, default=uuid.uuid4, serialize=False, editable=False, unique=True),
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in New Issue