mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 19:20:47 +02:00
Remove unused migration
This commit is contained in:
parent
7c89edce09
commit
e521309c43
4 changed files with 7 additions and 104 deletions
|
@ -325,7 +325,7 @@ SERVER_EMAIL = "root@get.gov"
|
|||
|
||||
# region: Waffle feature flags-----------------------------------------------------------###
|
||||
# If Waffle encounters a reference to a flag that is not in the database, should Waffle create the flag?
|
||||
WAFFLE_CREATE_MISSING_FLAGS = False
|
||||
WAFFLE_CREATE_MISSING_FLAGS = True
|
||||
|
||||
# The model that will be used to keep track of flags. Extends AbstractUserFlag.
|
||||
# Used to replace the default flag class (for customization purposes).
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
# This migration creates default WaffleFlag objects for our DB.
|
||||
# Whenever you add to the `create_waffle_flags` function, increment/copy this
|
||||
# migration by one
|
||||
|
||||
from django.db import migrations
|
||||
from registrar.models import WaffleFlag
|
||||
from typing import Any
|
||||
|
||||
|
||||
# For linting: RunPython expects a function reference,
|
||||
# so let's give it one
|
||||
def create_flags(apps, schema_editor):
|
||||
"""
|
||||
Populates pre-existing flags we wish to associate.
|
||||
Only generates a flag name and a note, but no other data is loaded at this point.
|
||||
"""
|
||||
|
||||
# This is a bit of a hack to get around "apps" not knowing what the concept of a constant is
|
||||
default_flags = WaffleFlag.get_default_waffle_flags()
|
||||
WaffleFlag.create_waffle_flags_for_migrations(apps, default_flags)
|
||||
|
||||
|
||||
def delete_flags(apps, schema_editor):
|
||||
"""
|
||||
Deletes all prexisting flags.
|
||||
Does not delete flags not defined in this scope (user generated).
|
||||
"""
|
||||
|
||||
# This is a bit of a hack to get around "apps" not knowing what the concept of a constant is
|
||||
default_flags = WaffleFlag.get_default_waffle_flags()
|
||||
WaffleFlag.delete_waffle_flags_for_migrations(apps, default_flags)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("registrar", "0090_waffleflag"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
code=create_flags,
|
||||
reverse_code=delete_flags,
|
||||
atomic=True,
|
||||
),
|
||||
]
|
|
@ -17,51 +17,3 @@ class WaffleFlag(AbstractUserFlag):
|
|||
|
||||
verbose_name = "waffle flag"
|
||||
verbose_name_plural = "Waffle flags"
|
||||
|
||||
@staticmethod
|
||||
def get_default_waffle_flags():
|
||||
"""
|
||||
Defines which waffle flags should be created at startup.
|
||||
|
||||
Add to this function if you want to add another flag that is generated at startup.
|
||||
When you do so, you will need to add a new instance of `0091_create_waffle_flags_v{version_number}`
|
||||
in registrar/migrations for that change to update automatically on migrate.
|
||||
"""
|
||||
default_flags = [
|
||||
# flag_name, flag_note
|
||||
("profile_feature", "Used for profiles"),
|
||||
("dns_hosting_feature", "Used for dns hosting"),
|
||||
]
|
||||
return default_flags
|
||||
|
||||
@staticmethod
|
||||
def create_waffle_flags_for_migrations(apps, default_waffle_flags):
|
||||
"""
|
||||
Creates a list of flags for our migrations.
|
||||
"""
|
||||
logger.info("Creating default waffle flags...")
|
||||
WaffleFlag = apps.get_model("registrar", "WaffleFlag")
|
||||
# Flags can be changed through django admin if necessary.
|
||||
for flag_name, flag_note in default_waffle_flags:
|
||||
try:
|
||||
WaffleFlag.objects.update_or_create(
|
||||
name=flag_name,
|
||||
# Booleans like superusers or is_staff can be set here, if needed.
|
||||
defaults={"note": flag_note},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred when attempting to add or update flag {flag_name}: {e}")
|
||||
|
||||
@staticmethod
|
||||
def delete_waffle_flags_for_migrations(apps, default_waffle_flags):
|
||||
"""
|
||||
Delete a list of flags for our migrations (the reverse_code operation).
|
||||
"""
|
||||
logger.info("Deleting default waffle flags...")
|
||||
WaffleFlag = apps.get_model("registrar", "WaffleFlag")
|
||||
existing_flags = WaffleFlag.objects.filter(name__in=default_waffle_flags)
|
||||
for flag in existing_flags:
|
||||
try:
|
||||
WaffleFlag.objects.get(name=flag.name).delete()
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred when attempting to delete flag {flag.name}: {e}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue