TP-0000 | DB migration (#13)

This commit is contained in:
Ravi Chandora
2023-04-12 00:14:47 +05:30
committed by GitHub Enterprise
parent 4f74943cf9
commit a74c7612ec
8 changed files with 224 additions and 1 deletions

20
Dockerfile.migrationDown Normal file
View File

@@ -0,0 +1,20 @@
#ARG GOLANG_TAG=193044292705.dkr.ecr.ap-south-1.amazonaws.com/common/golang:1.19
# To run locally, use
ARG GOLANG_TAG=registry.cmd.navi-tech.in/common/golang:1.19
FROM ${GOLANG_TAG} as builder
ARG DSN
ENV POSTGRES_DSN $DSN
RUN curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
RUN echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ bionic main" > /etc/apt/sources.list.d/migrate.list
RUN apt-get update
RUN apt-get install -y migrate
RUN mkdir -p /build
WORKDIR /build
COPY . /build
CMD /bin/bash -c "make migration-down POSTGRES_DSN=${POSTGRES_DSN}"

20
Dockerfile.migrationUp Normal file
View File

@@ -0,0 +1,20 @@
#ARG GOLANG_TAG=193044292705.dkr.ecr.ap-south-1.amazonaws.com/common/golang:1.19
# To run locally, use
ARG GOLANG_TAG=registry.cmd.navi-tech.in/common/golang:1.19
FROM ${GOLANG_TAG} as builder
ARG DSN
ENV POSTGRES_DSN $DSN
RUN curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
RUN echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ bionic main" > /etc/apt/sources.list.d/migrate.list
RUN apt-get update
RUN apt-get install -y migrate
RUN mkdir -p /build
WORKDIR /build
COPY . /build
CMD /bin/bash -c "make migration-up POSTGRES_DSN=${POSTGRES_DSN}"

View File

@@ -4,8 +4,16 @@ build:
.PHONY: docker-build
docker-build:
docker build -t houston -f Dockerfile .
docker build -t houston -f Dockerfile.houston .
.PHONY: docker-run
docker-run: docker-build
docker run houston
.PHONY: migration-up
migration-up:
migrate -path db/migration/ -database "${POSTGRES_DSN}?sslmode=disable" -verbose up
.PHONY: migration-down
migration-down:
migrate -path db/migration/ -database "${POSTGRES_DSN}?sslmode=disable" -verbose down

View File

@@ -0,0 +1,23 @@
drop table incident;
drop table team;
drop table team_tag;
drop table houston_user;
drop table severity;
drop table tag;
drop table tag_value;
drop table incident_status;
drop table role;
drop table incident_role;
drop table incident_channel;
drop table incident_tag;

View File

@@ -0,0 +1,148 @@
CREATE TABLE incident
(
id SERIAL PRIMARY KEY,
title text,
description text,
status integer not null,
severity_id integer not null,
incident_name text,
slack_channel varchar(100),
detection_time timestamp without time zone,
start_time timestamp without time zone,
end_time timestamp without time zone,
team_id int not null,
jira_id varchar(100),
confluence_id varchar(100),
created_by varchar(100),
updated_by varchar(100),
severity_tat timestamp without time zone,
remind_me_at timestamp without time zone,
enable_reminder boolean DEFAULT false,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
CREATE TABLE team
(
id SERIAL PRIMARY KEY,
name varchar(50) unique not null,
slack_user_ids varchar[] default '{}',
active boolean DEFAULT false,
version bigint default 0,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
create table team_tag
(
id serial primary key,
team_id int not null,
tag_id int not null,
optional boolean default false,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
CREATE TABLE houston_user
(
id SERIAL PRIMARY KEY,
name varchar(50),
slack_user_id varchar(100),
active boolean DEFAULT true
);
CREATE TABLE severity
(
id SERIAL PRIMARY KEY,
name varchar(50),
description text,
version bigint default 0,
sla int,
slack_user_ids varchar[] default '{}',
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
CREATE TABLE tag
(
id SERIAL PRIMARY KEY,
name varchar not null,
label text not null,
place_holder text,
action_id varchar(100) not null,
type varchar(100) not null,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
create table tag_value
(
id serial primary key,
tag_id int not null,
value varchar not null,
create_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
CREATE TABLE incident_status
(
id SERIAL PRIMARY KEY,
name varchar(50),
description text,
is_terminal_status boolean default false,
version bigint default 0,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
create table role
(
id serial primary key,
name varchar(100) not null,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
CREATE TABLE incident_role
(
id SERIAL PRIMARY KEY,
incident_id integer not null,
role varchar(100),
assigned_to varchar(100),
assigned_by varchar(100),
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
CREATE TABLE incident_channel
(
id SERIAL PRIMARY KEY,
slack_channel varchar(100),
incident_id int not null,
message_timestamp varchar(100),
version bigint default 0,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);
create table incident_tag
(
id serial primary key,
incident_id int not null,
tag_id int not null,
tag_value_ids int[] default '{}',
free_text_value text,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
);

1
go.mod
View File

@@ -51,6 +51,7 @@ require (
go.opentelemetry.io/otel v1.13.0 // indirect
go.opentelemetry.io/otel/trace v1.13.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/crypto v0.6.0 // indirect

View File

@@ -0,0 +1,3 @@
#!/bin/bash
migrate create -ext sql -dir db/migration -seq $1