init
This commit is contained in:
26
src/main/resources/db/migration/V10__.sql
Normal file
26
src/main/resources/db/migration/V10__.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
ALTER TABLE finance.users
|
||||
ALTER COLUMN created_at SEt DEFAULT now(),
|
||||
ALTER COLUMN updated_at SEt DEFAULT now();
|
||||
|
||||
ALTER TABLE finance.spaces
|
||||
ALTER COLUMN created_at SEt DEFAULT now(),
|
||||
ALTER COLUMN updated_at SEt DEFAULT now();
|
||||
|
||||
ALTER TABLE finance.transactions
|
||||
ALTER COLUMN type SET DATA TYPE VARCHAR(255),
|
||||
ALTER COLUMN kind SET DATA TYPE VARCHAR(255),
|
||||
ALTER COLUMN created_at SET DEFAULT now(),
|
||||
ALTER COLUMN updated_at SEt DEFAULT now();
|
||||
|
||||
|
||||
|
||||
ALTER TABLE finance.tokens
|
||||
ALTER COLUMN status SET DATA TYPE VARCHAR(255),
|
||||
ALTER COLUMN issued_at SET DEFAULT now();
|
||||
|
||||
|
||||
ALTER TABLE finance.categories_etalon
|
||||
ALTER COLUMN type SET DATA TYPE VARCHAR(255);
|
||||
|
||||
|
||||
|
||||
0
src/main/resources/db/migration/V11__.sql
Normal file
0
src/main/resources/db/migration/V11__.sql
Normal file
2
src/main/resources/db/migration/V12__.sql
Normal file
2
src/main/resources/db/migration/V12__.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
alter table finance.categories
|
||||
add column if not exists description varchar(1000);
|
||||
5
src/main/resources/db/migration/V13__.sql
Normal file
5
src/main/resources/db/migration/V13__.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
alter table finance.categories
|
||||
add column if not exists description varchar(1000);
|
||||
|
||||
alter table finance.categories
|
||||
alter column type set data type varchar;
|
||||
2
src/main/resources/db/migration/V14__.sql
Normal file
2
src/main/resources/db/migration/V14__.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT uq_categories_space_name UNIQUE (space_id, name);
|
||||
20
src/main/resources/db/migration/V15__.sql
Normal file
20
src/main/resources/db/migration/V15__.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
create table if not exists finance.recurrent_operations
|
||||
(
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
space_id INTEGER NOT NULL,
|
||||
category_id INTEGER NOT NULL,
|
||||
name VARCHAR(200) NOT NULL ,
|
||||
amount NUMERIC NOT NULL,
|
||||
date INTEGER NOT NULL,
|
||||
created_by_id INTEGER NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
||||
updated_by_id INTEGER NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE finance.recurrent_operations
|
||||
ADD CONSTRAINT FK_SPACE_ON_RECURRENT_OPERATIONS FOREIGN KEY (space_id) REFERENCES finance.spaces (id),
|
||||
ADD CONSTRAINT FK_CATEGORY_ON_RECURRENT_OPERATIONS FOREIGN KEY (category_id) REFERENCES finance.categories (id),
|
||||
ADD CONSTRAINT FK_CREATED_BY_ON_RECURRENT_OPERATIONS FOREIGN KEY (created_by_id) REFERENCES finance.users (id),
|
||||
ADD CONSTRAINT FK_UPDATED_BY_ON_RECURRENT_OPERATIONS FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
15
src/main/resources/db/migration/V16__.sql
Normal file
15
src/main/resources/db/migration/V16__.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
alter table finance.goals
|
||||
alter column space_id set data type integer;
|
||||
|
||||
create table if not exists finance.goals_components
|
||||
(
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
goal_id INTEGER NOT NULL,
|
||||
name VARCHAR(255) NOT NULL ,
|
||||
amount NUMERIC NOT NULL,
|
||||
is_done BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
date TIMESTAMP WITH TIME ZONE NULL
|
||||
);
|
||||
|
||||
alter table finance.goals_components
|
||||
add constraint fk_goal_on_components foreign key (goal_id) references finance.goals (id);
|
||||
19
src/main/resources/db/migration/V17__.sql
Normal file
19
src/main/resources/db/migration/V17__.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
drop table if exists finance.goals_components;
|
||||
create table if not exists finance.goals_components
|
||||
(
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
goal_id INTEGER NOT NULL,
|
||||
name VARCHAR(255) NOT NULL ,
|
||||
amount NUMERIC NOT NULL,
|
||||
is_done BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
date TIMESTAMP WITH TIME ZONE NULL,
|
||||
created_by_id INTEGER NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT now(),
|
||||
updated_by_id INTEGER NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NULL
|
||||
);
|
||||
|
||||
alter table finance.goals_components
|
||||
add constraint fk_goal_on_components foreign key (goal_id) references finance.goals (id),
|
||||
add constraint fk_created_by_on_components foreign key (created_by_id) references finance.users (id),
|
||||
add constraint fk_updated_by_on_components foreign key (updated_by_id) references finance.users (id);
|
||||
40
src/main/resources/db/migration/V18__.sql
Normal file
40
src/main/resources/db/migration/V18__.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
drop table if exists finance.categories CASCADE ;
|
||||
|
||||
CREATE TABLE finance.categories
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
space_id INTEGER NOT NULL,
|
||||
type SMALLINT NOT NULL ,
|
||||
name VARCHAR(255) NOT NULL ,
|
||||
description VARCHAR(1000) NOT NULL,
|
||||
icon VARCHAR(255) NOT NULL ,
|
||||
is_deleted BOOLEAN NOT NULL,
|
||||
created_by_id INTEGER NOT NULL ,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now(),
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
CONSTRAINT pk_categories PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_SPACE FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS finance.categories_etalon;
|
||||
|
||||
CREATE TABLE finance.categories_etalon
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
type SMALLINT NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description VARCHAR(1000) NOT NULL,
|
||||
icon VARCHAR(255) NOT NULL,
|
||||
CONSTRAINT pk_categories_etalon PRIMARY KEY (id)
|
||||
);
|
||||
40
src/main/resources/db/migration/V19__.sql
Normal file
40
src/main/resources/db/migration/V19__.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
drop table if exists finance.categories CASCADE ;
|
||||
|
||||
CREATE TABLE finance.categories
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
space_id INTEGER NOT NULL,
|
||||
type VARCHAR NOT NULL ,
|
||||
name VARCHAR(255) NOT NULL ,
|
||||
description VARCHAR(1000) NOT NULL,
|
||||
icon VARCHAR(255) NOT NULL ,
|
||||
is_deleted BOOLEAN NOT NULL,
|
||||
created_by_id INTEGER NOT NULL ,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now(),
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
CONSTRAINT pk_categories PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_SPACE FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS finance.categories_etalon;
|
||||
|
||||
CREATE TABLE finance.categories_etalon
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
type VARCHAR NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description VARCHAR(1000) NOT NULL,
|
||||
icon VARCHAR(255) NOT NULL,
|
||||
CONSTRAINT pk_categories_etalon PRIMARY KEY (id)
|
||||
);
|
||||
196
src/main/resources/db/migration/V1__.sql
Normal file
196
src/main/resources/db/migration/V1__.sql
Normal file
@@ -0,0 +1,196 @@
|
||||
CREATE TABLE finance.categories
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
space_id INTEGER,
|
||||
type SMALLINT,
|
||||
name VARCHAR(255),
|
||||
icon VARCHAR(255),
|
||||
is_deleted BOOLEAN NOT NULL,
|
||||
created_by_id INTEGER,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
CONSTRAINT pk_categories PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.currencies_ref
|
||||
(
|
||||
code VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(255),
|
||||
symbol VARCHAR(255),
|
||||
CONSTRAINT pk_currencies_ref PRIMARY KEY (code)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.currency_rates
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
currency_code VARCHAR(255),
|
||||
rate DECIMAL,
|
||||
date date,
|
||||
CONSTRAINT pk_currency_rates PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.goals
|
||||
(
|
||||
id VARCHAR(255) NOT NULL,
|
||||
space_id INTEGER,
|
||||
type SMALLINT,
|
||||
name VARCHAR(255),
|
||||
description VARCHAR(255),
|
||||
amount DECIMAL,
|
||||
until_date date,
|
||||
created_by_id INTEGER,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
current_amount DECIMAL,
|
||||
CONSTRAINT pk_goals PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.goals_transactions
|
||||
(
|
||||
goal_id VARCHAR(255) NOT NULL,
|
||||
transactions_id INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE finance.spaces
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
name VARCHAR(255),
|
||||
owner_id INTEGER,
|
||||
is_deleted BOOLEAN NOT NULL,
|
||||
created_by_id INTEGER,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
CONSTRAINT pk_spaces PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.spaces_participants
|
||||
(
|
||||
space_id INTEGER NOT NULL,
|
||||
participants_id INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE finance.subscriptions
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
user_id INTEGER,
|
||||
endpoint VARCHAR(255),
|
||||
auth VARCHAR(255),
|
||||
p256dh VARCHAR(255),
|
||||
is_active BOOLEAN NOT NULL,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
CONSTRAINT pk_subscriptions PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.tokens
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
token VARCHAR(255),
|
||||
user_id INTEGER,
|
||||
issued_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
expires_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
status SMALLINT,
|
||||
CONSTRAINT pk_tokens PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.transactions
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
space_id INTEGER,
|
||||
parent_id INTEGER,
|
||||
type SMALLINT,
|
||||
kind SMALLINT,
|
||||
category_id INTEGER,
|
||||
comment VARCHAR(255),
|
||||
amount DECIMAL,
|
||||
fees DECIMAL,
|
||||
date TIMESTAMP WITHOUT TIME ZONE,
|
||||
is_deleted BOOLEAN NOT NULL,
|
||||
created_by_id INTEGER,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
CONSTRAINT pk_transactions PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.users
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
username VARCHAR(255),
|
||||
first_name VARCHAR(255),
|
||||
tg_id VARCHAR(255),
|
||||
tg_user_name VARCHAR(255),
|
||||
password VARCHAR(255),
|
||||
is_active BOOLEAN NOT NULL,
|
||||
reg_date date,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
roles TEXT[],
|
||||
CONSTRAINT pk_users PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_SPACE FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.currency_rates
|
||||
ADD CONSTRAINT FK_CURRENCY_RATES_ON_CURRENCY_CODE FOREIGN KEY (currency_code) REFERENCES finance.currencies_ref (code);
|
||||
|
||||
ALTER TABLE finance.goals
|
||||
ADD CONSTRAINT FK_GOALS_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.goals
|
||||
ADD CONSTRAINT FK_GOALS_ON_SPACE FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.goals
|
||||
ADD CONSTRAINT FK_GOALS_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.spaces
|
||||
ADD CONSTRAINT FK_SPACES_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.spaces
|
||||
ADD CONSTRAINT FK_SPACES_ON_OWNER FOREIGN KEY (owner_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.spaces
|
||||
ADD CONSTRAINT FK_SPACES_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.subscriptions
|
||||
ADD CONSTRAINT FK_SUBSCRIPTIONS_ON_USER FOREIGN KEY (user_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.tokens
|
||||
ADD CONSTRAINT FK_TOKENS_ON_USER FOREIGN KEY (user_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.transactions
|
||||
ADD CONSTRAINT FK_TRANSACTIONS_ON_CATEGORY FOREIGN KEY (category_id) REFERENCES finance.categories (id);
|
||||
|
||||
ALTER TABLE finance.transactions
|
||||
ADD CONSTRAINT FK_TRANSACTIONS_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.transactions
|
||||
ADD CONSTRAINT FK_TRANSACTIONS_ON_PARENT FOREIGN KEY (parent_id) REFERENCES finance.transactions (id);
|
||||
|
||||
ALTER TABLE finance.transactions
|
||||
ADD CONSTRAINT FK_TRANSACTIONS_ON_SPACE FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.transactions
|
||||
ADD CONSTRAINT FK_TRANSACTIONS_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
ADD CONSTRAINT fk_goatra_on_goal FOREIGN KEY (goal_id) REFERENCES finance.goals (id);
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
ADD CONSTRAINT fk_goatra_on_transaction FOREIGN KEY (transactions_id) REFERENCES finance.transactions (id);
|
||||
|
||||
ALTER TABLE finance.spaces_participants
|
||||
ADD CONSTRAINT fk_spapar_on_space FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.spaces_participants
|
||||
ADD CONSTRAINT fk_spapar_on_user FOREIGN KEY (participants_id) REFERENCES finance.users (id);
|
||||
40
src/main/resources/db/migration/V20__.sql
Normal file
40
src/main/resources/db/migration/V20__.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
drop table if exists finance.categories CASCADE ;
|
||||
|
||||
CREATE TABLE finance.categories
|
||||
(
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL ,
|
||||
space_id INTEGER NOT NULL,
|
||||
type VARCHAR NOT NULL ,
|
||||
name VARCHAR(255) NOT NULL ,
|
||||
description VARCHAR(1000) NOT NULL,
|
||||
icon VARCHAR(255) NOT NULL ,
|
||||
is_deleted BOOLEAN NOT NULL,
|
||||
created_by_id INTEGER NOT NULL ,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now(),
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
CONSTRAINT pk_categories PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_SPACE FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.categories
|
||||
ADD CONSTRAINT FK_CATEGORIES_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS finance.categories_etalon;
|
||||
|
||||
CREATE TABLE finance.categories_etalon
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
type VARCHAR NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description VARCHAR(1000) NOT NULL,
|
||||
icon VARCHAR(255) NOT NULL,
|
||||
CONSTRAINT pk_categories_etalon PRIMARY KEY (id)
|
||||
);
|
||||
32
src/main/resources/db/migration/V21__.sql
Normal file
32
src/main/resources/db/migration/V21__.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
drop table if exists finance.transactions cascade;
|
||||
|
||||
create table finance.transactions
|
||||
(
|
||||
|
||||
id integer generated by default as identity not null,
|
||||
space_id integer
|
||||
constraint fk_transactions_on_space
|
||||
references spaces,
|
||||
parent_id integer
|
||||
constraint fk_transactions_on_parent
|
||||
references transactions,
|
||||
type varchar(255),
|
||||
kind varchar(255),
|
||||
category_id integer,
|
||||
comment varchar(255),
|
||||
amount numeric,
|
||||
fees numeric,
|
||||
date date,
|
||||
is_done boolean not null,
|
||||
is_deleted boolean not null,
|
||||
created_by_id integer
|
||||
constraint fk_transactions_on_createdby
|
||||
references users,
|
||||
created_at timestamp default now(),
|
||||
updated_by_id integer
|
||||
constraint fk_transactions_on_updatedby
|
||||
references users,
|
||||
updated_at timestamp default now(),
|
||||
|
||||
CONSTRAINT pk_transactions PRIMARY KEY (id)
|
||||
);
|
||||
3
src/main/resources/db/migration/V2__.sql
Normal file
3
src/main/resources/db/migration/V2__.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
ADD CONSTRAINT uc_goals_transactions_transactions UNIQUE (goal_id);
|
||||
8
src/main/resources/db/migration/V3__.sql
Normal file
8
src/main/resources/db/migration/V3__.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
DROP CONSTRAINT uc_goals_transactions_transactions;
|
||||
|
||||
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
ADD CONSTRAINT uc_goals_transactions_transactions UNIQUE (transactions_id);
|
||||
10
src/main/resources/db/migration/V4__.sql
Normal file
10
src/main/resources/db/migration/V4__.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
CREATE TABLE finance.categories_etalon
|
||||
(
|
||||
id INTEGER NOT NULL,
|
||||
type SMALLINT,
|
||||
name VARCHAR(255),
|
||||
icon VARCHAR(255),
|
||||
CONSTRAINT pk_categories_etalon PRIMARY KEY (id)
|
||||
);
|
||||
2
src/main/resources/db/migration/V5__.sql
Normal file
2
src/main/resources/db/migration/V5__.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
drop table finance.goals CASCADE;
|
||||
-- drop table finance.goals_transactions;
|
||||
1
src/main/resources/db/migration/V6__.sql
Normal file
1
src/main/resources/db/migration/V6__.sql
Normal file
@@ -0,0 +1 @@
|
||||
drop table finance.goals_transactions CASCADE;
|
||||
105
src/main/resources/db/migration/V7__.sql
Normal file
105
src/main/resources/db/migration/V7__.sql
Normal file
@@ -0,0 +1,105 @@
|
||||
|
||||
CREATE TABLE finance.goals
|
||||
(
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
space_id INTEGER,
|
||||
type SMALLINT,
|
||||
name VARCHAR(255),
|
||||
description VARCHAR(255),
|
||||
amount DECIMAL,
|
||||
until_date date,
|
||||
created_by_id INTEGER,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
updated_by_id INTEGER,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
current_amount DECIMAL,
|
||||
CONSTRAINT pk_goals PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE finance.goals_transactions
|
||||
(
|
||||
goal_id INTEGER NOT NULL,
|
||||
transactions_id INTEGER NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
ADD CONSTRAINT uc_goals_transactions_transactions UNIQUE (transactions_id);
|
||||
|
||||
ALTER TABLE finance.goals
|
||||
ADD CONSTRAINT FK_GOALS_ON_CREATEDBY FOREIGN KEY (created_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.goals
|
||||
ADD CONSTRAINT FK_GOALS_ON_SPACE FOREIGN KEY (space_id) REFERENCES finance.spaces (id);
|
||||
|
||||
ALTER TABLE finance.goals
|
||||
ADD CONSTRAINT FK_GOALS_ON_UPDATEDBY FOREIGN KEY (updated_by_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
ADD CONSTRAINT fk_goatra_on_goal FOREIGN KEY (goal_id) REFERENCES finance.goals (id);
|
||||
|
||||
ALTER TABLE finance.goals_transactions
|
||||
ADD CONSTRAINT fk_goatra_on_transaction FOREIGN KEY (transactions_id) REFERENCES finance.transactions (id);
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.categories_id_seq;
|
||||
ALTER TABLE finance.categories
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.categories
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.categories_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.categories_id_seq OWNED BY finance.categories.id;
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.categories_etalon_id_seq;
|
||||
ALTER TABLE finance.categories_etalon
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.categories_etalon
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.categories_etalon_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.categories_etalon_id_seq OWNED BY finance.categories_etalon.id;
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.currency_rates_id_seq;
|
||||
ALTER TABLE finance.currency_rates
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.currency_rates
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.currency_rates_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.currency_rates_id_seq OWNED BY finance.currency_rates.id;
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.spaces_id_seq;
|
||||
ALTER TABLE finance.spaces
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.spaces
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.spaces_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.spaces_id_seq OWNED BY finance.spaces.id;
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.subscriptions_id_seq;
|
||||
ALTER TABLE finance.subscriptions
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.subscriptions
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.subscriptions_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.subscriptions_id_seq OWNED BY finance.subscriptions.id;
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.tokens_id_seq;
|
||||
ALTER TABLE finance.tokens
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.tokens
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.tokens_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.tokens_id_seq OWNED BY finance.tokens.id;
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.transactions_id_seq;
|
||||
ALTER TABLE finance.transactions
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.transactions
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.transactions_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.transactions_id_seq OWNED BY finance.transactions.id;
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS finance.users_id_seq;
|
||||
ALTER TABLE finance.users
|
||||
ALTER COLUMN id SET NOT NULL;
|
||||
ALTER TABLE finance.users
|
||||
ALTER COLUMN id SET DEFAULT nextval('finance.users_id_seq');
|
||||
|
||||
ALTER SEQUENCE finance.users_id_seq OWNED BY finance.users.id;
|
||||
8
src/main/resources/db/migration/V8__.sql
Normal file
8
src/main/resources/db/migration/V8__.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE finance.transactions
|
||||
ADD is_done BOOLEAN;
|
||||
|
||||
ALTER TABLE finance.transactions
|
||||
ALTER COLUMN is_done SET NOT NULL;
|
||||
|
||||
ALTER TABLE finance.spaces_participants
|
||||
ADD CONSTRAINT pk_spaces_participants PRIMARY KEY (space_id, participants_id);
|
||||
5
src/main/resources/db/migration/V9__.sql
Normal file
5
src/main/resources/db/migration/V9__.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE finance.categories
|
||||
ALTER COLUMN created_at SEt DEFAULT now();
|
||||
ALTER TABLE finance.categories
|
||||
ALTER COLUMN updated_at SEt DEFAULT now();
|
||||
|
||||
Reference in New Issue
Block a user