-- Tesla Fleet API: VIN na vozidle, aktivace api_type pro Model Y (home-01), -- singleton tabulka tokenů (refresh token Tesla ROTUJE při každém použití — -- nelze ho držet jen v .env, runtime hodnota žije zde; .env je jen seed). alter table ems.asset_vehicle add column if not exists vin text; comment on column ems.asset_vehicle.vin is 'VIN pro párování s vozidlem v API výrobce (Tesla Fleet). NULL = doplní se automaticky při prvním úspěšném čtení (jediné vozidlo na účtu), jinak nutno vyplnit ručně.'; update ems.asset_vehicle set api_type = 'tesla' where code = 'tesla-my' and site_id = (select id from ems.site where code = 'home-01'); create table if not exists ems.tesla_token ( id int primary key default 1 check (id = 1), refresh_token text not null, access_token text, access_expires_at timestamptz, updated_at timestamptz not null default now() ); comment on table ems.tesla_token is 'Singleton: aktuální Tesla Fleet API tokeny. Seed refresh tokenu z env TESLA_REFRESH_TOKEN při prvním použití; rotace ukládá fn_tesla_token_upsert.';