postgresql & migrations

This commit is contained in:
yash 2026-02-25 20:22:13 +03:00
parent ae096d4820
commit 7f6cd8e557
15 changed files with 254 additions and 27 deletions

View file

@ -0,0 +1,4 @@
drop table if exists alert;
drop table if exists instrument;
drop table if exists currency;
drop table if exists users;

View 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'));

View file

@ -0,0 +1,8 @@
package migrations
import (
"embed"
)
//go:embed *.sql
var Folder embed.FS