generated from alecodes/base-template
refactor!: change migration tool to sqlx
This commit is contained in:
parent
27037a9f75
commit
49c8682164
15 changed files with 30 additions and 894 deletions
1
migrations/20250415185052_initial.down.sql
Normal file
1
migrations/20250415185052_initial.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
-- Add down migration script here
|
||||
1
migrations/20250415185052_initial.up.sql
Normal file
1
migrations/20250415185052_initial.up.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
-- Add up migration script here
|
||||
2
migrations/20250415185421_create_table_sources.down.sql
Normal file
2
migrations/20250415185421_create_table_sources.down.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
-- Add down migration script here
|
||||
DROP TABLE public.sources;
|
||||
10
migrations/20250415185421_create_table_sources.up.sql
Normal file
10
migrations/20250415185421_create_table_sources.up.sql
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
-- Add up migration script here
|
||||
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
|
||||
);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
-- Add down migration script here
|
||||
DROP TABLE public.logic_groups;
|
||||
12
migrations/20250415185456_create_table_logic_groups.up.sql
Normal file
12
migrations/20250415185456_create_table_logic_groups.up.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
-- Add up migration script here
|
||||
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)
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
-- Add down migration script here
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
-- Add up migration script here
|
||||
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);
|
||||
4
migrations/20250415190938_create_table_entries.down.sql
Normal file
4
migrations/20250415190938_create_table_entries.down.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
-- Add down migration script here
|
||||
DROP TABLE public.entries;
|
||||
|
||||
DROP schema entries_partitions;
|
||||
72
migrations/20250415190938_create_table_entries.up.sql
Normal file
72
migrations/20250415190938_create_table_entries.up.sql
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
-- Add up migration script here
|
||||
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');
|
||||
Loading…
Add table
Add a link
Reference in a new issue