<?php

return <<<'SQL'
CREATE TABLE survey_publications (
    id CHAR(36) NOT NULL PRIMARY KEY,
    tenant_id CHAR(36) NOT NULL,
    survey_id CHAR(36) NOT NULL,
    version_no INT NOT NULL DEFAULT 1,
    title VARCHAR(255) NOT NULL,
    member_visible TINYINT(1) NOT NULL DEFAULT 1,
    published_by VARCHAR(255) NOT NULL,
    published_at DATETIME NOT NULL,
    snapshot_json LONGTEXT NOT NULL,
    results_json LONGTEXT NOT NULL,
    response_count INT NOT NULL DEFAULT 0,
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL,
    UNIQUE (survey_id, version_no),
    FOREIGN KEY (tenant_id) REFERENCES tenants(id),
    FOREIGN KEY (survey_id) REFERENCES surveys(id)
);
SQL;
