ALTER TABLE export_templates
ALTER COLUMN max_row_count DROP DEFAULT,
ALTER COLUMN max_row_count DROP NOT NULL,

ALTER COLUMN header_row DROP DEFAULT,
ALTER COLUMN header_row DROP NOT NULL,

ALTER COLUMN data_start_row DROP DEFAULT,
ALTER COLUMN data_start_row DROP NOT NULL,

ALTER COLUMN data_end_row DROP DEFAULT,
ALTER COLUMN data_end_row DROP NOT NULL;



CREATE TABLE export_template_excel_sheet_details (
    id SERIAL PRIMARY KEY,
    export_template_id INTEGER NOT NULL,
    sheet_name VARCHAR(100) NOT NULL,

    max_row_count INTEGER NULL,
    header_row INTEGER NULL,
    data_start_row INTEGER NULL,
    data_end_row INTEGER NULL,

    status_id INTEGER NOT NULL DEFAULT 1,
    company_id INTEGER NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),

    CONSTRAINT export_template_excel_sheet_details_status_id_fkey
        FOREIGN KEY (status_id)
        REFERENCES statuses(id)
        ON DELETE CASCADE,

    CONSTRAINT export_template_excel_sheet_details_export_template_fkey
        FOREIGN KEY (company_id, export_template_id)
        REFERENCES export_templates(company_id, id)
        ON DELETE CASCADE,

    CONSTRAINT export_template_excel_sheet_details_company_id_id_key
        UNIQUE (company_id, id),

    CONSTRAINT export_template_excel_sheet_details_company_id_export_template_id_sheet_name_key
        UNIQUE (company_id, export_template_id, sheet_name)
);



ALTER TABLE export_template_queries
ADD COLUMN sheet_name VARCHAR(255);

ALTER TABLE export_template_line_items
ADD COLUMN sheet_name VARCHAR(255);