-- V034 Enterprise Deployment, Observability and Implementation Wizard
CREATE TABLE IF NOT EXISTS implementation_projects_v034 (id varchar(36) PRIMARY KEY,tenant_id varchar(36) NOT NULL,name varchar(180) NOT NULL,status varchar(30) NOT NULL,current_step varchar(80) NOT NULL,progress_percent integer NOT NULL,checklist json NOT NULL,configuration json NOT NULL,owner_id varchar(36) NOT NULL,started_at timestamp,completed_at timestamp);
CREATE TABLE IF NOT EXISTS platform_diagnostic_runs_v034 (id varchar(36) PRIMARY KEY,tenant_id varchar(36),scope varchar(40),status varchar(30),score integer,checks json,recommendations json,started_by varchar(36),started_at timestamp,finished_at timestamp);
CREATE TABLE IF NOT EXISTS native_backup_runs_v034 (id varchar(36) PRIMARY KEY,tenant_id varchar(36),backup_type varchar(30),status varchar(30),file_path text,checksum_sha256 varchar(64),size_bytes bigint,encrypted boolean,error_message text,started_by varchar(36),started_at timestamp,finished_at timestamp);
CREATE TABLE IF NOT EXISTS platform_releases_v034 (id varchar(36) PRIMARY KEY,version varchar(40) UNIQUE,channel varchar(30),package_path text,checksum_sha256 varchar(64),changelog text,status varchar(30),created_by varchar(36),created_at timestamp);
CREATE TABLE IF NOT EXISTS platform_update_runs_v034 (id varchar(36) PRIMARY KEY,release_id varchar(36),status varchar(30),previous_version varchar(40),target_version varchar(40),backup_run_id varchar(36),rollback_available boolean,log json,requested_by varchar(36),requested_at timestamp,finished_at timestamp);
ALTER TABLE implementation_projects_v034 ENABLE ROW LEVEL SECURITY;
ALTER TABLE implementation_projects_v034 FORCE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation_implementation_v034 ON implementation_projects_v034 USING (tenant_id::text=current_setting('app.current_tenant_id',true)) WITH CHECK (tenant_id::text=current_setting('app.current_tenant_id',true));
