-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Database migration (closes #29)
- Loading branch information
Showing
13 changed files
with
213 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
wrestling_scoreboard_server/database/migration/v0.0.1-beta.14_Initial-migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
create table migration | ||
( | ||
semver varchar(127) default '0.0.0'::character varying not null | ||
); | ||
alter table migration owner to wrestling; | ||
INSERT INTO public.migration (semver) VALUES ('0.0.0'); | ||
|
||
CREATE TYPE public.user_privilege AS ENUM ( | ||
'none', | ||
'read', | ||
'write', | ||
'admin' | ||
); | ||
ALTER TYPE public.user_privilege OWNER TO wrestling; | ||
|
||
alter table public.bout add organization_id integer; | ||
|
||
alter table public.division_weight_class add organization_id integer; | ||
alter table public.division_weight_class add org_sync_id varchar(127); | ||
|
||
alter table public.league add bout_days integer DEFAULT 14 NOT NULL; | ||
|
||
CREATE TABLE public.secured_user ( | ||
id integer NOT NULL, | ||
username character varying(127) NOT NULL, | ||
password_hash bytea NOT NULL, | ||
email character varying(127), | ||
person_id integer, | ||
salt character varying(127) NOT NULL, | ||
created_at date NOT NULL, | ||
privilege public.user_privilege DEFAULT 'none'::public.user_privilege NOT NULL | ||
); | ||
ALTER TABLE public.secured_user OWNER TO wrestling; | ||
|
||
CREATE SEQUENCE public.user_id_seq | ||
AS integer | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
ALTER SEQUENCE public.user_id_seq OWNER TO wrestling; | ||
ALTER SEQUENCE public.user_id_seq OWNED BY public.secured_user.id; | ||
ALTER TABLE ONLY public.secured_user ALTER COLUMN id SET DEFAULT nextval('public.user_id_seq'::regclass); | ||
|
||
COPY public.secured_user (id, username, password_hash, email, person_id, salt, created_at, privilege) FROM stdin; | ||
1 admin \\xb2950268d52c1d17f1b35edd35c071be3d320b488c81425c6b144340963e524a \N 924VOg== 2024-08-25 admin | ||
\. | ||
|
||
SELECT pg_catalog.setval('public.user_id_seq', 1, true); | ||
|
||
ALTER TABLE ONLY public.secured_user ADD CONSTRAINT user_pk PRIMARY KEY (id); | ||
ALTER TABLE ONLY public.secured_user ADD CONSTRAINT user_pk_2 UNIQUE (username); | ||
|
||
ALTER TABLE ONLY public.bout ADD CONSTRAINT bout_organization_id_fk FOREIGN KEY (organization_id) REFERENCES public.organization(id); | ||
ALTER TABLE ONLY public.division_weight_class ADD CONSTRAINT division_weight_class_organization_id_fk FOREIGN KEY (organization_id) REFERENCES public.organization(id); | ||
|
||
ALTER TABLE ONLY public.secured_user ADD CONSTRAINT user_person_id_fk FOREIGN KEY (person_id) REFERENCES public.person(id) ON DELETE CASCADE; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:dotenv/dotenv.dart' show DotEnv; | ||
import 'package:logging/logging.dart'; | ||
|
||
final env = Environment(); | ||
|
||
class Environment { | ||
late final Level? logLevel; | ||
late final String? host; | ||
late final int? port; | ||
late final String? jwtSecret; | ||
late final int? jwtExpiresInDays; | ||
late final String? jwtIssuer; | ||
late final String? databaseHost; | ||
late final int? databasePort; | ||
late final String? databaseUser; | ||
late final String? databasePassword; | ||
late final String? databaseName; | ||
late final String? corsAllowOrigin; | ||
late final int? webSocketPingIntervalSecs; | ||
|
||
Environment() { | ||
final dotEnv = DotEnv(); | ||
dotEnv.load(); // Load dotenv variables | ||
logLevel = Level.LEVELS.where((level) => level.name == dotEnv['LOG_LEVEL']?.toUpperCase()).singleOrNull; | ||
host = dotEnv['HOST']; | ||
port = int.tryParse(dotEnv['PORT'] ?? ''); | ||
jwtSecret = dotEnv['JWT_SECRET']; | ||
jwtExpiresInDays = int.tryParse(dotEnv['JWT_EXPIRES_IN_DAYS'] ?? ''); | ||
jwtIssuer = dotEnv['JWT_ISSUER']; | ||
databaseHost = dotEnv['DATABASE_HOST']; | ||
databasePort = int.tryParse(dotEnv['DATABASE_PORT'] ?? ''); | ||
databaseUser = dotEnv['DATABASE_USER']; | ||
databasePassword = dotEnv['DATABASE_PASSWORD']; | ||
databaseName = dotEnv['DATABASE_NAME']; | ||
corsAllowOrigin = dotEnv['CORS_ALLOW_ORIGIN']; | ||
webSocketPingIntervalSecs = int.tryParse(dotEnv['WEB_SOCKET_PING_INTERVAL_SECS'] ?? ''); | ||
} | ||
} |
Oops, something went wrong.