Drop data migrations setting up demo tokens
This commit is contained in:
parent
1cd8de2e23
commit
9f89897264
5 changed files with 0 additions and 390 deletions
|
|
@ -1,178 +0,0 @@
|
|||
# Generated by Django 3.2.5 on 2021-08-04 10:42
|
||||
|
||||
import sys
|
||||
from django.db import migrations
|
||||
from django.utils import timezone, dateparse
|
||||
from apps.alerts.models.alert_receive_channel import number_to_smiles_translator
|
||||
from apps.public_api import constants as public_api_constants
|
||||
|
||||
|
||||
TYPE_SINGLE_EVENT = 0
|
||||
TYPE_RECURRENT_EVENT = 1
|
||||
FREQUENCY_WEEKLY = 1
|
||||
SOURCE_TERRAFORM = 3
|
||||
STEP_WAIT = 0
|
||||
STEP_NOTIFY_USERS_QUEUE = 12
|
||||
SOURCE_WEB = 1
|
||||
|
||||
|
||||
def create_demo_token_instances(apps, schema_editor):
|
||||
if not (len(sys.argv) > 1 and sys.argv[1] == 'test'):
|
||||
User = apps.get_model('user_management', 'User')
|
||||
Organization = apps.get_model('user_management', 'Organization')
|
||||
AlertReceiveChannel = apps.get_model('alerts', 'AlertReceiveChannel')
|
||||
EscalationChain = apps.get_model('alerts', 'EscalationChain')
|
||||
ChannelFilter = apps.get_model('alerts', 'ChannelFilter')
|
||||
EscalationPolicy = apps.get_model('alerts', 'EscalationPolicy')
|
||||
OnCallScheduleICal = apps.get_model('schedules', 'OnCallScheduleICal')
|
||||
AlertGroup = apps.get_model('alerts', 'AlertGroup')
|
||||
Alert = apps.get_model('alerts', 'Alert')
|
||||
CustomButton = apps.get_model("alerts", "CustomButton")
|
||||
CustomOnCallShift = apps.get_model('schedules', 'CustomOnCallShift')
|
||||
|
||||
organization = Organization.objects.get(public_primary_key=public_api_constants.DEMO_ORGANIZATION_ID)
|
||||
user = User.objects.get(public_primary_key=public_api_constants.DEMO_USER_ID)
|
||||
|
||||
alert_receive_channel, _ = AlertReceiveChannel.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_INTEGRATION_ID,
|
||||
defaults=dict(
|
||||
integration=0,
|
||||
author=user,
|
||||
organization=organization,
|
||||
smile_code=number_to_smiles_translator(0)
|
||||
)
|
||||
)
|
||||
escalation_chain, _ = EscalationChain.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ESCALATION_CHAIN_ID,
|
||||
defaults=dict(
|
||||
name="default",
|
||||
organization=organization,
|
||||
)
|
||||
)
|
||||
|
||||
channel_filter_1, _ = ChannelFilter.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ROUTE_ID_1,
|
||||
defaults=dict(
|
||||
alert_receive_channel=alert_receive_channel,
|
||||
slack_channel_id=public_api_constants.DEMO_SLACK_CHANNEL_FOR_ROUTE_ID,
|
||||
filtering_term='us-(east|west)',
|
||||
order=0,
|
||||
escalation_chain=escalation_chain,
|
||||
)
|
||||
)
|
||||
ChannelFilter.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ROUTE_ID_2,
|
||||
defaults=dict(
|
||||
alert_receive_channel=alert_receive_channel,
|
||||
slack_channel_id=public_api_constants.DEMO_SLACK_CHANNEL_FOR_ROUTE_ID,
|
||||
filtering_term='.*',
|
||||
order=1,
|
||||
is_default=True,
|
||||
escalation_chain=escalation_chain,
|
||||
)
|
||||
)
|
||||
|
||||
EscalationPolicy.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ESCALATION_POLICY_ID_1,
|
||||
defaults=dict(
|
||||
step=STEP_WAIT,
|
||||
wait_delay=timezone.timedelta(minutes=1),
|
||||
order=0,
|
||||
escalation_chain=escalation_chain,
|
||||
)
|
||||
)
|
||||
|
||||
escalation_policy_1, _ = EscalationPolicy.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ESCALATION_POLICY_ID_2,
|
||||
defaults=dict(
|
||||
step=STEP_NOTIFY_USERS_QUEUE,
|
||||
order=1,
|
||||
escalation_chain=escalation_chain,
|
||||
)
|
||||
)
|
||||
escalation_policy_1.notify_to_users_queue.add(user)
|
||||
|
||||
schedule, _ = OnCallScheduleICal.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_SCHEDULE_ID_ICAL,
|
||||
defaults=dict(
|
||||
organization=organization,
|
||||
name=public_api_constants.DEMO_SCHEDULE_NAME_ICAL,
|
||||
ical_url_overrides=public_api_constants.DEMO_SCHEDULE_ICAL_URL_OVERRIDES,
|
||||
channel=public_api_constants.DEMO_SLACK_CHANNEL_SLACK_ID,
|
||||
)
|
||||
)
|
||||
|
||||
alert_group, _ = AlertGroup.all_objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_INCIDENT_ID,
|
||||
defaults=dict(
|
||||
channel=alert_receive_channel,
|
||||
channel_filter=channel_filter_1,
|
||||
resolved=True,
|
||||
resolved_at=dateparse.parse_datetime(public_api_constants.DEMO_INCIDENT_RESOLVED_AT),
|
||||
)
|
||||
)
|
||||
alert_group.started_at = dateparse.parse_datetime(public_api_constants.DEMO_INCIDENT_CREATED_AT)
|
||||
alert_group.save(update_fields=['started_at'])
|
||||
|
||||
for id, created_at in public_api_constants.DEMO_ALERT_IDS:
|
||||
alert, _ = Alert.objects.get_or_create(
|
||||
public_primary_key=id,
|
||||
defaults=dict(
|
||||
group=alert_group,
|
||||
raw_request_data=public_api_constants.DEMO_ALERT_PAYLOAD,
|
||||
title='Memory above 90% threshold',
|
||||
)
|
||||
)
|
||||
alert.created_at = dateparse.parse_datetime(created_at)
|
||||
alert.save(update_fields=['created_at'])
|
||||
|
||||
CustomButton.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_CUSTOM_ACTION_ID,
|
||||
defaults=dict(
|
||||
name=public_api_constants.DEMO_CUSTOM_ACTION_NAME,
|
||||
organization=organization,
|
||||
)
|
||||
)
|
||||
|
||||
on_call_shift_1, _ = CustomOnCallShift.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ON_CALL_SHIFT_ID_1,
|
||||
defaults=dict(
|
||||
type=TYPE_SINGLE_EVENT,
|
||||
organization=organization,
|
||||
name=public_api_constants.DEMO_ON_CALL_SHIFT_NAME_1,
|
||||
start=dateparse.parse_datetime(public_api_constants.DEMO_ON_CALL_SHIFT_START_1),
|
||||
duration=timezone.timedelta(seconds=public_api_constants.DEMO_ON_CALL_SHIFT_DURATION),
|
||||
)
|
||||
)
|
||||
|
||||
on_call_shift_1.users.add(user)
|
||||
|
||||
on_call_shift_2, _ = CustomOnCallShift.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ON_CALL_SHIFT_ID_2,
|
||||
defaults=dict(
|
||||
type=TYPE_RECURRENT_EVENT,
|
||||
organization=organization,
|
||||
name=public_api_constants.DEMO_ON_CALL_SHIFT_NAME_2,
|
||||
start=dateparse.parse_datetime(public_api_constants.DEMO_ON_CALL_SHIFT_START_2),
|
||||
duration=timezone.timedelta(seconds=public_api_constants.DEMO_ON_CALL_SHIFT_DURATION),
|
||||
frequency=FREQUENCY_WEEKLY,
|
||||
interval=2,
|
||||
by_day=public_api_constants.DEMO_ON_CALL_SHIFT_BY_DAY,
|
||||
source=SOURCE_TERRAFORM,
|
||||
)
|
||||
)
|
||||
|
||||
on_call_shift_2.users.add(user)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('alerts', '0002_squashed_initial'),
|
||||
('user_management', '0002_squashed_create_demo_token_instances'),
|
||||
('schedules', '0002_squashed_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_demo_token_instances, migrations.RunPython.noop)
|
||||
]
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
# Generated by Django 3.2.5 on 2021-08-04 13:02
|
||||
|
||||
import sys
|
||||
from django.db import migrations
|
||||
|
||||
from apps.auth_token import constants
|
||||
from apps.auth_token import crypto
|
||||
from apps.public_api import constants as public_api_constants
|
||||
|
||||
|
||||
def create_demo_token_instances(apps, schema_editor):
|
||||
if not (len(sys.argv) > 1 and sys.argv[1] == 'test'):
|
||||
User = apps.get_model('user_management', 'User')
|
||||
Organization = apps.get_model('user_management', 'Organization')
|
||||
ApiAuthToken = apps.get_model('auth_token', 'ApiAuthToken')
|
||||
|
||||
organization = Organization.objects.get(public_primary_key=public_api_constants.DEMO_ORGANIZATION_ID)
|
||||
user = User.objects.get(public_primary_key=public_api_constants.DEMO_USER_ID)
|
||||
|
||||
token_string = crypto.generate_token_string()
|
||||
digest = crypto.hash_token_string(token_string)
|
||||
|
||||
ApiAuthToken.objects.get_or_create(
|
||||
name=public_api_constants.DEMO_AUTH_TOKEN,
|
||||
user=user,
|
||||
organization=organization,
|
||||
defaults=dict(token_key=token_string[:constants.TOKEN_KEY_LENGTH], digest=digest)
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth_token', '0002_squashed_initial'),
|
||||
('user_management', '0002_squashed_create_demo_token_instances')
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_demo_token_instances, migrations.RunPython.noop)
|
||||
]
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
# Generated by Django 3.2.5 on 2021-08-04 10:45
|
||||
|
||||
import sys
|
||||
from django.db import migrations
|
||||
from django.utils import timezone
|
||||
from apps.public_api import constants as public_api_constants
|
||||
|
||||
|
||||
STEP_WAIT = 0
|
||||
STEP_NOTIFY = 1
|
||||
NOTIFY_BY_SMS = 1
|
||||
NOTIFY_BY_PHONE = 2
|
||||
FIVE_MINUTES = timezone.timedelta(minutes=5)
|
||||
|
||||
|
||||
def create_demo_token_instances(apps, schema_editor):
|
||||
if not (len(sys.argv) > 1 and sys.argv[1] == 'test'):
|
||||
User = apps.get_model('user_management', 'User')
|
||||
UserNotificationPolicy = apps.get_model("base", "UserNotificationPolicy")
|
||||
|
||||
user = User.objects.get(public_primary_key=public_api_constants.DEMO_USER_ID)
|
||||
|
||||
UserNotificationPolicy.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_PERSONAL_NOTIFICATION_ID_1,
|
||||
defaults=dict(
|
||||
important=False,
|
||||
user=user,
|
||||
notify_by=NOTIFY_BY_SMS,
|
||||
step=STEP_NOTIFY,
|
||||
order=0,
|
||||
)
|
||||
)
|
||||
UserNotificationPolicy.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_PERSONAL_NOTIFICATION_ID_2,
|
||||
defaults=dict(
|
||||
important=False,
|
||||
user=user,
|
||||
step=STEP_WAIT,
|
||||
wait_delay=FIVE_MINUTES,
|
||||
order=1,
|
||||
)
|
||||
)
|
||||
UserNotificationPolicy.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_PERSONAL_NOTIFICATION_ID_3,
|
||||
defaults=dict(
|
||||
important=False,
|
||||
user=user,
|
||||
step=STEP_NOTIFY,
|
||||
notify_by=NOTIFY_BY_PHONE,
|
||||
order=2,
|
||||
)
|
||||
)
|
||||
|
||||
UserNotificationPolicy.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_PERSONAL_NOTIFICATION_ID_4,
|
||||
defaults=dict(
|
||||
important=True,
|
||||
user=user,
|
||||
notify_by=NOTIFY_BY_PHONE,
|
||||
order=0,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0002_squashed_initial'),
|
||||
('user_management', '0002_squashed_create_demo_token_instances')
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_demo_token_instances, migrations.RunPython.noop)
|
||||
]
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
# Generated by Django 3.2.5 on 2021-08-04 10:51
|
||||
|
||||
import sys
|
||||
from django.db import migrations
|
||||
from apps.public_api import constants as public_api_constants
|
||||
|
||||
|
||||
def create_demo_token_instances(apps, schema_editor):
|
||||
if not (len(sys.argv) > 1 and sys.argv[1] == 'test'):
|
||||
SlackUserIdentity = apps.get_model('slack', 'SlackUserIdentity')
|
||||
SlackTeamIdentity = apps.get_model('slack', 'SlackTeamIdentity')
|
||||
SlackChannel = apps.get_model('slack', 'SlackChannel')
|
||||
SlackUserGroup = apps.get_model("slack", "SlackUserGroup")
|
||||
|
||||
slack_team_identity, _ = SlackTeamIdentity.objects.get_or_create(
|
||||
slack_id=public_api_constants.DEMO_SLACK_TEAM_ID,
|
||||
)
|
||||
SlackUserIdentity.objects.get_or_create(
|
||||
slack_id=public_api_constants.DEMO_SLACK_USER_ID,
|
||||
slack_team_identity=slack_team_identity,
|
||||
)
|
||||
|
||||
SlackChannel.objects.get_or_create(
|
||||
name=public_api_constants.DEMO_SLACK_CHANNEL_NAME,
|
||||
slack_id=public_api_constants.DEMO_SLACK_CHANNEL_SLACK_ID,
|
||||
slack_team_identity=slack_team_identity,
|
||||
)
|
||||
|
||||
SlackUserGroup.objects.get_or_create(
|
||||
slack_team_identity=slack_team_identity,
|
||||
slack_id=public_api_constants.DEMO_SLACK_USER_GROUP_SLACK_ID,
|
||||
public_primary_key=public_api_constants.DEMO_SLACK_USER_GROUP_ID,
|
||||
name=public_api_constants.DEMO_SLACK_USER_GROUP_NAME,
|
||||
handle=public_api_constants.DEMO_SLACK_USER_GROUP_HANDLE,
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('slack', '0002_squashed_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_demo_token_instances, migrations.RunPython.noop)
|
||||
]
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
# Generated by Django 3.2.5 on 2021-08-04 10:46
|
||||
|
||||
import sys
|
||||
from django.db import migrations
|
||||
from apps.public_api import constants as public_api_constants
|
||||
from common.constants.role import Role
|
||||
|
||||
|
||||
def create_demo_token_instances(apps, schema_editor):
|
||||
if not (len(sys.argv) > 1 and sys.argv[1] == 'test'):
|
||||
SlackUserIdentity = apps.get_model('slack', 'SlackUserIdentity')
|
||||
SlackTeamIdentity = apps.get_model('slack', 'SlackTeamIdentity')
|
||||
User = apps.get_model('user_management', 'User')
|
||||
Organization = apps.get_model('user_management', 'Organization')
|
||||
|
||||
slack_team_identity = SlackTeamIdentity.objects.get(slack_id=public_api_constants.DEMO_SLACK_TEAM_ID)
|
||||
slack_user_identity = SlackUserIdentity.objects.get(
|
||||
slack_id=public_api_constants.DEMO_SLACK_USER_ID,
|
||||
slack_team_identity=slack_team_identity,
|
||||
)
|
||||
|
||||
organization, _ = Organization.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_ORGANIZATION_ID,
|
||||
defaults=dict(
|
||||
slack_team_identity=slack_team_identity,
|
||||
org_id=0, stack_id=0,
|
||||
)
|
||||
)
|
||||
User.objects.get_or_create(
|
||||
public_primary_key=public_api_constants.DEMO_USER_ID,
|
||||
defaults=dict(
|
||||
username=public_api_constants.DEMO_USER_USERNAME,
|
||||
email=public_api_constants.DEMO_USER_EMAIL,
|
||||
organization=organization,
|
||||
role=Role.ADMIN,
|
||||
slack_user_identity=slack_user_identity,
|
||||
user_id=0,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('user_management', '0001_squashed_initial'),
|
||||
('slack', '0003_squashed_create_demo_token_instances'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_demo_token_instances, migrations.RunPython.noop)
|
||||
]
|
||||
Loading…
Add table
Reference in a new issue