Files
plane/web/core/local-db/utils/tables.ts
Satish Gandham 9fb353ef54 [WEB-2706] chore: Switch to wa-sqlite (#5859)
* fix layout switching when filter is not yet completely fetched

* add layout in issue filter params

* Handle cases when DB intilization failed

* chore: permission layer and updated issues v1 query from workspace to project level

* - Switch to using wa-sqlite instead of sqlite-wasm

* Code cleanup and fix indexes

* Add missing files

* - Import only required functions from sentry
- Wait till all the tables are created

* Skip workspace sync if one is already in progress.

* Sync workspace without using transaction

* Minor cleanup

* Close DB connection before deleting files
Fix clear OPFS on safari

* Fix type issue

* Improve issue insert performance

* Refactor workspace sync

* Close the DB connection while switching workspaces

* Update web/core/local-db/worker/db.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Worker cleanup and error handling

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update web/core/local-db/worker/db.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update web/core/local-db/storage.sqlite.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update web/core/local-db/worker/db.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Code cleanup

* Set default order by to created at and descending

* Wait for transactions to complete.

---------

Co-authored-by: rahulramesha <rahulramesham@gmail.com>
Co-authored-by: gurusainath <gurusainath007@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-10-24 15:35:02 +05:30

42 lines
1.4 KiB
TypeScript

import { persistence } from "../storage.sqlite";
import {
labelSchema,
moduleSchema,
Schema,
issueMetaSchema,
issueSchema,
stateSchema,
cycleSchema,
estimatePointSchema,
memberSchema,
optionsSchema,
} from "./schemas";
import { log } from "./utils";
const createTableSQLfromSchema = (tableName: string, schema: Schema) => {
let sql = `CREATE TABLE IF NOT EXISTS ${tableName} (`;
sql += Object.keys(schema)
.map((key) => `'${key}' ${schema[key]}`)
.join(", ");
sql += `);`;
log("#####", sql);
return sql;
};
export const createTables = async () => {
//@todo use promise.all or send all statements in one go
await persistence.db.exec("BEGIN;");
await persistence.db.exec(createTableSQLfromSchema("issues", issueSchema));
await persistence.db.exec(createTableSQLfromSchema("issue_meta", issueMetaSchema));
await persistence.db.exec(createTableSQLfromSchema("modules", moduleSchema));
await persistence.db.exec(createTableSQLfromSchema("labels", labelSchema));
await persistence.db.exec(createTableSQLfromSchema("states", stateSchema));
await persistence.db.exec(createTableSQLfromSchema("cycles", cycleSchema));
await persistence.db.exec(createTableSQLfromSchema("estimate_points", estimatePointSchema));
await persistence.db.exec(createTableSQLfromSchema("members", memberSchema));
await persistence.db.exec(createTableSQLfromSchema("options", optionsSchema));
await persistence.db.exec("COMMIT;");
};