mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
django: Rename DB tables from plinth_ to freedombox_
- Migration files have already been renamed from plinth/migrations/*.py to freedombox/migrations/*.py. When running these migrations, ensure that database tables are first created with plinth_* names rather than freedombox_*. This is because we want the database progression path for fresh installations (with not tables) as well as the old installation (with plinth_ tables) to be the same. To achieve this, migrations.CreateModel will be provided with db_table=plinth_* values. - Ensure if a migration call (plinth, 0001_initial) ran, then the (freedombox, 0001_initial) is not run again. This is achieved by adding replaces = [] in the newly renamed migration. - Create a new migration that renames plinth_* tables to freedombox_*. - Fix an old migration (0003) to use historic model rather than current model. This ensure that it uses the plinth_ table during migration rather than freedombox_ table. Tests: - Delete the database and start plinth.service with all the patches. Notice that the database migration (fresh creation) works well. First setup, first wizard, bepasty app installation, and notifications work as expected. Notice that django_migrations table contains entries for (plinth,000[1-6]*) as well as (freedombox,000[1-7]*). - Delete the database and start plinth.service without the patches. Run first setup and wizard. Install bepasty. Then apply the patches and restart plinth.service. Notice that the database migration (renaming of tables) works well. First setup is already done. First wizard is not shown. bepasty is shown as installed. Previously shown notifications are retained . Notice that django_migrations table contains entries for (plinth,000[1-6]*) as well as (freedombox,000[1-7]*). - Delete the database and start plinth.service from trixie version. Run first setup and wizard. Install bepasty. Then apply the patches and restart plinth.service. Notice that the database migration (renaming of tables) works well. First setup is already done. First wizard is not shown. bepasty is shown as installed. Previously shown notifications are retained . Notice that django_migrations table contains entries for (plinth,000[1-6]*) as well as (freedombox,000[1-7]*). Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
3587f49703
commit
3af63bbf21
@ -19,9 +19,14 @@ class Migration(migrations.Migration):
|
||||
|
||||
dependencies: list = []
|
||||
|
||||
replaces = [
|
||||
('plinth', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='KVStore',
|
||||
options={'db_table': 'plinth_kvstore'},
|
||||
fields=[
|
||||
('key', models.TextField(primary_key=True, serialize=False)),
|
||||
('value_json', models.TextField()),
|
||||
|
||||
@ -11,9 +11,14 @@ class Migration(migrations.Migration):
|
||||
('freedombox', '0001_initial'),
|
||||
]
|
||||
|
||||
replaces = [
|
||||
('plinth', '0002_modulestore'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Module',
|
||||
options={'db_table': 'plinth_module'},
|
||||
fields=[
|
||||
('name', models.TextField(primary_key=True, serialize=False)),
|
||||
('setup_version', models.IntegerField()),
|
||||
|
||||
@ -8,8 +8,6 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
from freedombox.models import KVStore
|
||||
|
||||
|
||||
def merge_firstboot_finished_fields(apps, schema_editor):
|
||||
"""
|
||||
@ -18,6 +16,8 @@ def merge_firstboot_finished_fields(apps, schema_editor):
|
||||
'firstboot_completed' is the most accurate name for now, and by combining
|
||||
the fields we do not have to deal with legacy states/fields anymore.
|
||||
"""
|
||||
KVStore = apps.get_model('freedombox', 'KVStore')
|
||||
|
||||
# Get and remove 'firstboot_state'
|
||||
firstboot_state = 0
|
||||
try:
|
||||
@ -62,6 +62,10 @@ class Migration(migrations.Migration):
|
||||
('freedombox', '0002_modulestore'),
|
||||
]
|
||||
|
||||
replaces = [
|
||||
('plinth', '0003_merge_firstboot_completed_fields'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(merge_firstboot_finished_fields),
|
||||
]
|
||||
|
||||
@ -27,9 +27,14 @@ class Migration(migrations.Migration):
|
||||
('freedombox', '0003_merge_firstboot_completed_fields'),
|
||||
]
|
||||
|
||||
replaces = [
|
||||
('plinth', '0004_userprofile'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UserProfile',
|
||||
options={'db_table': 'plinth_userprofile'},
|
||||
fields=[
|
||||
('id',
|
||||
models.AutoField(auto_created=True, primary_key=True,
|
||||
|
||||
@ -18,9 +18,14 @@ class Migration(migrations.Migration):
|
||||
('freedombox', '0004_userprofile'),
|
||||
]
|
||||
|
||||
replaces = [
|
||||
('plinth', '0005_storednotification'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='StoredNotification',
|
||||
options={'db_table': 'plinth_storednotification'},
|
||||
fields=[
|
||||
('id',
|
||||
models.CharField(max_length=128, primary_key=True,
|
||||
|
||||
@ -19,9 +19,14 @@ class Migration(migrations.Migration):
|
||||
('freedombox', '0005_storednotification'),
|
||||
]
|
||||
|
||||
replaces = [
|
||||
('plinth', '0006_userpasskey'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UserPasskey',
|
||||
options={'db_table': 'plinth_userpasskey'},
|
||||
fields=[
|
||||
('id',
|
||||
models.AutoField(auto_created=True, primary_key=True,
|
||||
|
||||
24
freedombox/migrations/0007_rename_plinth_to_freedombox.py
Normal file
24
freedombox/migrations/0007_rename_plinth_to_freedombox.py
Normal file
@ -0,0 +1,24 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
Django migration for renaming all the DB tables from plinth_ to freedombox_.
|
||||
"""
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('freedombox', '0006_userpasskey'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelTable(name='KVStore', table='freedombox_kvstore'),
|
||||
migrations.AlterModelTable(name='Module', table='freedombox_module'),
|
||||
migrations.AlterModelTable(name='UserProfile',
|
||||
table='freedombox_userprofile'),
|
||||
migrations.AlterModelTable(name='StoredNotification',
|
||||
table='freedombox_storednotification'),
|
||||
migrations.AlterModelTable(name='UserPasskey',
|
||||
table='freedombox_userpasskey'),
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user