postgresql & migrations
This commit is contained in:
parent
ae096d4820
commit
7f6cd8e557
15 changed files with 254 additions and 27 deletions
|
|
@ -0,0 +1,4 @@
|
|||
drop table if exists alert;
|
||||
drop table if exists instrument;
|
||||
drop table if exists currency;
|
||||
drop table if exists users;
|
||||
32
internal/repository/postgresql/migrations/000001_init.up.sql
Normal file
32
internal/repository/postgresql/migrations/000001_init.up.sql
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
create table if not exists users (
|
||||
id uuid primary key not null default gen_random_uuid(),
|
||||
telegram_id bigint not null UNIQUE
|
||||
);
|
||||
|
||||
create table if not exists currency (
|
||||
id serial primary key not null,
|
||||
symbol text not null UNIQUE
|
||||
-- decimals integer not null
|
||||
);
|
||||
|
||||
create table if not exists instrument (
|
||||
id uuid primary key not null default gen_random_uuid(),
|
||||
base_currency_id integer references currency(id) not null,
|
||||
quoted_currency_id integer references currency(id) not null,
|
||||
CHECK (base_currency_id <> quoted_currency_id),
|
||||
UNIQUE (base_currency_id, quoted_currency_id)
|
||||
);
|
||||
|
||||
create table if not exists alert (
|
||||
id uuid primary key not null default gen_random_uuid(),
|
||||
instrument_id uuid references instrument(id) not null,
|
||||
price text not null,
|
||||
active bool not null default true
|
||||
);
|
||||
|
||||
insert into currency(symbol) values ('USDT'), ('BTC'), ('ETH'), ('SOL');
|
||||
|
||||
insert into instrument (base_currency_id, quoted_currency_id) values
|
||||
((select id from currency where symbol = 'BTC'), (select id from currency where symbol = 'USDT')),
|
||||
((select id from currency where symbol = 'ETH'), (select id from currency where symbol = 'USDT')),
|
||||
((select id from currency where symbol = 'SOL'), (select id from currency where symbol = 'USDT'));
|
||||
8
internal/repository/postgresql/migrations/embed.go
Normal file
8
internal/repository/postgresql/migrations/embed.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"embed"
|
||||
)
|
||||
|
||||
//go:embed *.sql
|
||||
var Folder embed.FS
|
||||
Loading…
Add table
Add a link
Reference in a new issue