DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'tgAccountStatus') THEN CREATE TYPE TgAccountStatus AS ENUM ('active', 'inactive', 'ban'); END IF; END $$; CREATE TABLE IF NOT EXISTS tgAccounts ( id bigserial primary key , ApiID integer not null, ApiHash text not null , PhoneNumber text not null , Password text not null , Status TgAccountStatus not null, Deleted bool not null default false, CreatedAt timestamp not null default current_timestamp ); CREATE UNIQUE INDEX idx_apiid_apihash ON tgAccounts (ApiID, ApiHash) WHERE Deleted = false;