CREATE TABLE IF NOT EXISTS YclientsTokens (
    AccountID VARCHAR(30) PRIMARY KEY,
    SalonID int not null,                 -- ID компании
    AccessToken TEXT NOT NULL DEFAULT '',
    Active BOOLEAN NOT NULL DEFAULT FALSE,
    Expiration BOOLEAN NOT NULL DEFAULT FALSE, -- флаг истек ли токен
    CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

create UNIQUE INDEX idx_unique_tokens_yclients ON YclientsTokens (SalonID, AccountID) WHERE Active = true and Expiration = false;

ALTER TABLE YclientsAccounts
ADD COLUMN IF NOT EXISTS ShortDecription text NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS Country VARCHAR(50) NOT NULL DEFAULT '';

ALTER TABLE YclientsTimeSlots
ALTER COLUMN DatesSettings SET DEFAULT '{}'::jsonb;

UPDATE YclientsTimeSlots
SET DatesSettings = '{}'::jsonb
WHERE DatesSettings = '[]'::jsonb;

ALTER TABLE YclientsServices
ALTER COLUMN PriceMin TYPE TEXT,
ALTER COLUMN PriceMax TYPE TEXT,
ALTER COLUMN Discount TYPE TEXT;