import { Schema, Column, Section, Expr } from "@mwater/expressions"; import ConditionsExprCompiler from "./ConditionsExprCompiler"; import { Form } from "./form"; import { IndicatorCalculation } from "."; import { FormDesign, Item } from "./formDesign"; /** Adds a form to a mwater-expressions schema * * NOTE: The exact order of the columns is very important as query optimized responses depend on the precise schema. * * To add or remove or change any of the items in this, you must de-optimize and re-optimize all forms! Use query_optimize_form.ts with --recompute flag * * e.g. from mwater-server directory: * * ./run_script.sh scripts/query_optimize_form.ts --db=postgres://postgres:PASSWORD@localhost:54320/mwater_prod --recompute_all * * to do it immediately. * * or * * ./run_script.sh scripts/query_optimize_form.ts --db=postgres://postgres:PASSWORD@localhost:54320/mwater_prod --recompute_all_lazy * * to do it via the cron job. * * This is because we keep an optimized copy of responses for optimized forms in a plain table for speed, * one table per form (+ one for each roster). These much be in sync with the schema. * */ export default class FormSchemaBuilder { /** indicators is at least all indicators referenced in indicator calculations. Can be empty and indicator calculations will be omitted */ addForm(schema: Schema, form: Form, cloneFormsDeprecated?: boolean, isAdmin?: boolean, indicators?: any): Schema; addReverseJoins(schema: Schema, form: Form, reverseJoins: { table: string; column: Column; }[]): Schema; addRosterTables(schema: Schema, design: FormDesign, conditionsExprCompiler: ConditionsExprCompiler, reverseJoins: any, tableId: string): Schema; addIndicatorCalculations(schema: Schema, form: Form, indicators: any[]): Schema; createIndicatorCalculationSection(indicatorCalculation: IndicatorCalculation, schema: Schema, indicators: any[], form: Form): Section | null; addConfidentialDataForRosters(schema: Schema, form: Form, conditionsExprCompiler: ConditionsExprCompiler): Schema; addConfidentialData(schema: Schema, form: Form, conditionsExprCompiler: ConditionsExprCompiler): Schema; addFormItem(options: { item: Item | FormDesign; contents: any; tableId: string; conditionsExprCompiler?: ConditionsExprCompiler; existingConditionExpr?: Expr; reverseJoins?: { table: string; column: Column; }[]; confidentialData?: boolean; }): any; addCalculations(schema: Schema, form: Form): Schema; }