Files
khb_microservices/packages/khb_common/migrations/031_qbo_connection.sql
2026-11-16 22:19:06 +03:00

21 lines
1.4 KiB
SQL

-- Подключение к QuickBooks Online (сервис qbo_auth): токены приложения и одноразовые state авторизации.
-- Токены хранятся зашифрованными (AES-256-GCM, ключ qbo_auth.encryptionKey в settings.json5), не в открытом виде.
create table if not exists qbo_connection (
environment text primary key check (environment in ('sandbox', 'production')),
realm_id text not null, -- идентификатор компании QuickBooks
access_token_enc text not null,
refresh_token_enc text not null,
access_expires_at timestamptz not null, -- access token живёт 60 минут
refresh_expires_at timestamptz not null, -- refresh token скользящий, до 100 дней
authorized_at timestamptz not null, -- когда администратор дал согласие
refreshed_at timestamptz not null,
status text not null default 'ok' check (status in ('ok', 'reauth_needed'))
);
create table if not exists qbo_oauth_state (
state text primary key,
environment text not null check (environment in ('sandbox', 'production')),
created_at timestamptz not null default now()
);
alter table qbo_connection enable row level security;
alter table qbo_oauth_state enable row level security;