-- Подключение к 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;