crypto_alert_bot/internal/repository/postgresql/migrations/000001_init.up.sql

37 lines
1.4 KiB
MySQL
Raw Normal View History

2026-02-25 20:22:13 +03:00
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)
);
2026-02-25 23:52:21 +03:00
create type alert_condition as enum ('above', 'below');
2026-02-25 20:22:13 +03:00
create table if not exists alert (
id uuid primary key not null default gen_random_uuid(),
2026-02-25 22:48:23 +03:00
user_id uuid references users(id) not null,
2026-02-25 20:22:13 +03:00
instrument_id uuid references instrument(id) not null,
price text not null,
2026-02-25 23:52:21 +03:00
active bool not null default true,
condition alert_condition not null
2026-02-25 20:22:13 +03:00
);
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'));