generated from alecodes/base-template
feat: add database service as dev dependency
This commit is contained in:
parent
5362d2ba30
commit
ca2ea91976
9 changed files with 1047 additions and 0 deletions
13
db/migrations/20250205190533_create_sources_table.sql
Normal file
13
db/migrations/20250205190533_create_sources_table.sql
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
-- migrate:up
|
||||
CREATE TABLE public.sources (
|
||||
id serial PRIMARY KEY,
|
||||
name character varying(20) NOT NULL,
|
||||
uid character varying(8) NOT NULL,
|
||||
uri character varying,
|
||||
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp with time zone,
|
||||
deleted_at timestamp with time zone
|
||||
);
|
||||
|
||||
-- migrate:down
|
||||
DROP TABLE public.sources;
|
||||
15
db/migrations/20250206220324_create_logic_groups_table.sql
Normal file
15
db/migrations/20250206220324_create_logic_groups_table.sql
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
-- migrate:up
|
||||
CREATE TABLE public.logic_groups (
|
||||
id serial PRIMARY KEY,
|
||||
name character varying(20) NOT NULL,
|
||||
uid character varying(8) NOT NULL,
|
||||
uri character varying,
|
||||
source_id int,
|
||||
created_at timestamp WITH time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp WITH time zone,
|
||||
deleted_at timestamp WITH time zone,
|
||||
CONSTRAINT fk_source FOREIGN KEY (source_id) REFERENCES public.sources(id)
|
||||
);
|
||||
|
||||
-- migrate:down
|
||||
DROP TABLE public.logic_groups;
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
-- migrate:up
|
||||
CREATE TABLE public.desambiguator_types(
|
||||
id serial PRIMARY KEY,
|
||||
name varchar(15) NOT NULL,
|
||||
input_type varchar(15) NOT NULL,
|
||||
placeholder varchar(30),
|
||||
created_at timestamp WITH time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp WITH time zone,
|
||||
deleted_at timestamp WITH time zone
|
||||
);
|
||||
|
||||
INSERT INTO
|
||||
public.desambiguator_types(name, input_type, placeholder)
|
||||
VALUES
|
||||
('Text', 'text', 'XXX-XXX-XXX'),
|
||||
('Date', 'date', '2020-12-31');
|
||||
|
||||
ALTER TABLE
|
||||
public.sources
|
||||
ADD
|
||||
COLUMN desambiguator_type_id int NOT NULL DEFAULT 1;
|
||||
|
||||
ALTER TABLE
|
||||
public.sources
|
||||
ADD
|
||||
CONSTRAINT fk_desambiguator_type FOREIGN KEY (desambiguator_type_id) REFERENCES public.desambiguator_types(id);
|
||||
|
||||
-- migrate:down
|
||||
ALTER TABLE
|
||||
public.sources DROP CONSTRAINT fk_desambiguator_type;
|
||||
|
||||
ALTER TABLE
|
||||
public.sources DROP COLUMN desambiguator_type_id;
|
||||
|
||||
DROP TABLE public.desambiguator_types;
|
||||
77
db/migrations/20250207174953_add_table_entries.sql
Normal file
77
db/migrations/20250207174953_add_table_entries.sql
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
-- migrate:up
|
||||
CREATE TABLE public.entries (
|
||||
id serial NOT NULL,
|
||||
uid varchar NOT NULL,
|
||||
desambiguator text NOT NULL,
|
||||
text text,
|
||||
logic_group_id integer NOT NULL,
|
||||
created_at timestamp WITH time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp WITH time zone,
|
||||
deleted_at timestamp WITH time zone,
|
||||
PRIMARY KEY (id, created_at),
|
||||
CONSTRAINT fk_logic_group FOREIGN KEY (logic_group_id) REFERENCES public.logic_groups(id)
|
||||
) PARTITION BY RANGE (created_at);
|
||||
|
||||
CREATE INDEX index_entries_uid ON ONLY public.entries USING btree (uid);
|
||||
|
||||
CREATE SCHEMA entries_partitions;
|
||||
|
||||
CREATE TABLE entries_partitions.e2020 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2020-01-01') TO ('2021-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2021 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2021-01-01') TO ('2022-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2022 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2022-01-01') TO ('2023-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2023 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2023-01-01') TO ('2024-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2024 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2024-01-01') TO ('2025-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2025 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2025-01-01') TO ('2026-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2026 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2026-01-01') TO ('2027-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2027 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2027-01-01') TO ('2028-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2028 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2028-01-01') TO ('2029-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2029 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2029-01-01') TO ('2030-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2030 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2030-01-01') TO ('2031-01-01');
|
||||
|
||||
-- migrate:down
|
||||
DROP TABLE public.entries;
|
||||
|
||||
DROP schema entries_partitions;
|
||||
Loading…
Add table
Add a link
Reference in a new issue