Skip to content

Commit

Permalink
Provision RDS database for Workshop Signups
Browse files Browse the repository at this point in the history
  • Loading branch information
adelaydeelsevier committed Mar 28, 2023
1 parent a0cb329 commit 73fcf98
Show file tree
Hide file tree
Showing 26 changed files with 305 additions and 314 deletions.
55 changes: 0 additions & 55 deletions database/README.md

This file was deleted.

Empty file removed database/conf/.gitkeep
Empty file.
89 changes: 0 additions & 89 deletions database/flyway.sh

This file was deleted.

31 changes: 0 additions & 31 deletions database/pg_dump_local_db.sh

This file was deleted.

71 changes: 0 additions & 71 deletions database/pgsanity.sh

This file was deleted.

2 changes: 0 additions & 2 deletions database/pgsanity/install-pgsanity.sh

This file was deleted.

7 changes: 0 additions & 7 deletions database/script.conf

This file was deleted.

4 changes: 0 additions & 4 deletions database/template/flyway.conf.local.template

This file was deleted.

5 changes: 0 additions & 5 deletions database/template/flyway.conf.template

This file was deleted.

5 changes: 0 additions & 5 deletions database/utils/.colors

This file was deleted.

32 changes: 29 additions & 3 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
@task
def terraform(context, account_number="", contact="", distribution_bucket="terraform-deployments",
attendees_table="attendees-datastore", input_queue="attendee-input-queue", project_name="clams",
region="us-east-1", environment="nonprod", lambdas="yes", frontend="yes", mode="plan"):
if mode not in ['init','plan', 'apply', 'destroy']:
region="us-east-1", environment="nonprod", lambdas="yes", frontend="yes", flywayonly="no",
database="yes", mode="plan"):
if mode not in ['init', 'plan', 'apply', 'destroy']:
print("No action to take. Try passing --mode init|plan|apply|destroy")
exit(-1)

if flywayonly == 'yes':
apply_database_schema()
exit(0)

if mode == 'apply' and lambdas == 'yes':
build_lambdas()

Expand Down Expand Up @@ -51,6 +56,9 @@ def terraform(context, account_number="", contact="", distribution_bucket="terra
with do_in_directory('terraform'):
local(command)

if mode == 'apply' and database == 'yes':
apply_database_schema()

if mode == 'apply' and frontend == 'yes':
build_and_deploy_frontend()

Expand All @@ -77,7 +85,7 @@ def get_api_url() -> str:


def build_lambdas():
for f in ['attendees-api', 'attendee-writer']:
for f in ['attendees-api', 'attendee-writer', 'processor']:
lambda_location = 'functions/{function}'.format(function=f)
print("Building lambda in {l}....".format(l=lambda_location))
with do_in_directory(lambda_location):
Expand Down Expand Up @@ -113,6 +121,24 @@ def deploy_frontend():
local('aws s3 cp frontend/public s3://clams.events.hacktionlab.org --recursive')


def apply_database_schema():
with do_in_directory('terraform'):
db_host = local('terraform output -raw rds_database_host').stdout
db_name = local('terraform output -raw rds_database_name').stdout
db_username = local('terraform output -raw rds_database_username').stdout
db_password = local('terraform output -raw rds_database_password').stdout

with do_in_directory('flyway'):
flyway_command = 'flyway -user={db_username} -password={db_password} ' \
'-url=jdbc:postgresql://{db_host}:5432/{db_name} migrate' \
.format(db_username=db_username,
db_password=db_password,
db_host=db_host,
db_name=db_name)
print("Executing command: ", flyway_command, "\n")
local(flyway_command)


@contextlib.contextmanager
def do_in_directory(directory: str):
CWD = os.getcwd()
Expand Down
2 changes: 2 additions & 0 deletions flyway/conf/flyway.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flyway.schemas=hacktionlab_workshops
flyway.validateOnMigrate=false
11 changes: 6 additions & 5 deletions database/sql/V1__Initial.sql → flyway/sql/V1__Initial.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
set timezone = 'UTC';

create schema if not exists "hacktionlab_workshops";
set schema 'hacktionlab_workshops';

create table workshops
create table hacktionlab_workshops.workshops
(
id serial primary key,
title text unique not null
);

create table people
create table hacktionlab_workshops.people
(
id serial primary key,
forename varchar(50) null,
surname varchar(50) null,
email varchar(100) unique not null
);

create table roles
create table hacktionlab_workshops.roles
(
id serial primary key,
role_name varchar(20) null
);

create table workshop_signups
create table hacktionlab_workshops.workshop_signups
(
id serial primary key,
people_id int not null,
Expand All @@ -39,7 +40,7 @@ create table workshop_signups
);

create sequence trigger_notifications_id_seq as bigint start 1 increment 1 cache 1;
create table trigger_notifications
create table hacktionlab_workshops.trigger_notifications
(
id bigint not null default nextval('trigger_notifications_id_seq'),
message varchar(256) not null,
Expand Down
Loading

0 comments on commit 73fcf98

Please sign in to comment.