From 920a81fcd9effcd183e4f4dc99086a6f9a5c3097 Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 1 Apr 2025 18:52:52 +0400 Subject: [PATCH] Inline migrations (#37) Signed-off-by: Kristina Fefelova --- README.md | 28 ++- bun.lock | 54 ++--- package.json | 8 +- packages/client-query/package.json | 2 +- packages/cockroach/migrations/00_schema.sql | 1 - packages/cockroach/migrations/01_message.sql | 35 ---- packages/cockroach/migrations/02_patch.sql | 16 -- packages/cockroach/migrations/03_files.sql | 20 -- packages/cockroach/migrations/04_reaction.sql | 14 -- packages/cockroach/migrations/05_thread.sql | 15 -- .../cockroach/migrations/06_notification.sql | 38 ---- packages/cockroach/package.json | 2 +- packages/cockroach/src/adapter.ts | 2 + packages/cockroach/src/init.ts | 194 ++++++++++++++++++ packages/query/package.json | 2 +- packages/rest-client/package.json | 2 +- packages/sdk-types/package.json | 2 +- packages/server/package.json | 2 +- packages/shared/package.json | 2 +- packages/types/package.json | 2 +- packages/yaml/package.json | 2 +- 21 files changed, 263 insertions(+), 180 deletions(-) delete mode 100644 packages/cockroach/migrations/00_schema.sql delete mode 100644 packages/cockroach/migrations/01_message.sql delete mode 100644 packages/cockroach/migrations/02_patch.sql delete mode 100644 packages/cockroach/migrations/03_files.sql delete mode 100644 packages/cockroach/migrations/04_reaction.sql delete mode 100644 packages/cockroach/migrations/05_thread.sql delete mode 100644 packages/cockroach/migrations/06_notification.sql create mode 100644 packages/cockroach/src/init.ts diff --git a/README.md b/README.md index 4c327ea3b3..f08e34d66c 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# Platform communication package \ No newline at end of file +## 📡 Platform Communication Package + +A modular communication package for platform-level messaging — +built with [Bun](https://bun.sh). + +--- + +### 📦 Installation + +Install dependencies using Bun: + +```bash + bun install +``` + +### Build packages + +```bash + bun run bundle +``` + +### Lint & format + +```bash + bun run lint + bun run format +``` \ No newline at end of file diff --git a/bun.lock b/bun.lock index fc721f8680..8c3ba13521 100644 --- a/bun.lock +++ b/bun.lock @@ -5,18 +5,18 @@ "name": "@hcengineering/communication", "devDependencies": { "@eslint/js": "^9.23.0", - "@types/bun": "^1.2.5", - "bun-types": "^1.2.5", + "@types/bun": "^1.2.8", + "bun-types": "^1.2.8", "eslint": "^9.23.0", "eslint-config-prettier": "^9.1.0", - "eslint-plugin-prettier": "^5.2.4", + "eslint-plugin-prettier": "^5.2.5", "prettier": "^3.5.3", - "typescript-eslint": "^8.27.0", + "typescript-eslint": "^8.29.0", }, }, "packages/client-query": { "name": "@hcengineering/communication-client-query", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/communication-query": "workspace:*", "@hcengineering/communication-sdk-types": "workspace:*", @@ -32,7 +32,7 @@ }, "packages/cockroach": { "name": "@hcengineering/communication-cockroach", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/communication-sdk-types": "workspace:*", "@hcengineering/communication-shared": "workspace:*", @@ -49,7 +49,7 @@ }, "packages/query": { "name": "@hcengineering/communication-query", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/communication-sdk-types": "workspace:*", "@hcengineering/communication-shared": "workspace:*", @@ -67,7 +67,7 @@ }, "packages/rest-client": { "name": "@hcengineering/communication-rest-client", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/communication-sdk-types": "workspace:*", "@hcengineering/communication-shared": "workspace:*", @@ -85,7 +85,7 @@ }, "packages/sdk-types": { "name": "@hcengineering/communication-sdk-types", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/communication-types": "workspace:*", "@hcengineering/core": "^0.7.28", @@ -99,7 +99,7 @@ }, "packages/server": { "name": "@hcengineering/communication-server", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/account-client": "^0.7.28", "@hcengineering/communication-cockroach": "workspace:*", @@ -120,7 +120,7 @@ }, "packages/shared": { "name": "@hcengineering/communication-shared", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/communication-types": "workspace:*", }, @@ -133,7 +133,7 @@ }, "packages/types": { "name": "@hcengineering/communication-types", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/card": "^0.7.28", "@hcengineering/core": "^0.7.28", @@ -147,7 +147,7 @@ }, "packages/yaml": { "name": "@hcengineering/communication-yaml", - "version": "0.1.147", + "version": "0.1.150", "dependencies": { "@hcengineering/communication-shared": "workspace:*", "@hcengineering/communication-types": "workspace:*", @@ -257,7 +257,7 @@ "@types/body-parser": ["@types/body-parser@1.19.5", "", { "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg=="], - "@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="], + "@types/bun": ["@types/bun@1.2.8", "", { "dependencies": { "bun-types": "1.2.7" } }, "sha512-t8L1RvJVUghW5V+M/fL3Thbxcs0HwNsXsnTEBEfEVqGteiJToOlZ/fyOEaR1kZsNqnu+3XA4RI/qmnX4w6+S+w=="], "@types/connect": ["@types/connect@3.4.38", "", { "dependencies": { "@types/node": "*" } }, "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug=="], @@ -295,21 +295,21 @@ "@types/ws": ["@types/ws@8.18.0", "", { "dependencies": { "@types/node": "*" } }, "sha512-8svvI3hMyvN0kKCJMvTJP/x6Y/EoQbepff882wL+Sn5QsXb3etnamgrJq4isrBxSJj5L2AuXcI0+bgkoAXGUJw=="], - "@typescript-eslint/eslint-plugin": ["@typescript-eslint/eslint-plugin@8.27.0", "", { "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.27.0", "@typescript-eslint/type-utils": "8.27.0", "@typescript-eslint/utils": "8.27.0", "@typescript-eslint/visitor-keys": "8.27.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", "ts-api-utils": "^2.0.1" }, "peerDependencies": { "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-4henw4zkePi5p252c8ncBLzLce52SEUz2Ebj8faDnuUXz2UuHEONYcJ+G0oaCF+bYCWVZtrGzq3FD7YXetmnSA=="], + "@typescript-eslint/eslint-plugin": ["@typescript-eslint/eslint-plugin@8.29.0", "", { "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.29.0", "@typescript-eslint/type-utils": "8.29.0", "@typescript-eslint/utils": "8.29.0", "@typescript-eslint/visitor-keys": "8.29.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", "ts-api-utils": "^2.0.1" }, "peerDependencies": { "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-PAIpk/U7NIS6H7TEtN45SPGLQaHNgB7wSjsQV/8+KYokAb2T/gloOA/Bee2yd4/yKVhPKe5LlaUGhAZk5zmSaQ=="], - "@typescript-eslint/parser": ["@typescript-eslint/parser@8.27.0", "", { "dependencies": { "@typescript-eslint/scope-manager": "8.27.0", "@typescript-eslint/types": "8.27.0", "@typescript-eslint/typescript-estree": "8.27.0", "@typescript-eslint/visitor-keys": "8.27.0", "debug": "^4.3.4" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-XGwIabPallYipmcOk45DpsBSgLC64A0yvdAkrwEzwZ2viqGqRUJ8eEYoPz0CWnutgAFbNMPdsGGvzjSmcWVlEA=="], + "@typescript-eslint/parser": ["@typescript-eslint/parser@8.29.0", "", { "dependencies": { "@typescript-eslint/scope-manager": "8.29.0", "@typescript-eslint/types": "8.29.0", "@typescript-eslint/typescript-estree": "8.29.0", "@typescript-eslint/visitor-keys": "8.29.0", "debug": "^4.3.4" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-8C0+jlNJOwQso2GapCVWWfW/rzaq7Lbme+vGUFKE31djwNncIpgXD7Cd4weEsDdkoZDjH0lwwr3QDQFuyrMg9g=="], - "@typescript-eslint/scope-manager": ["@typescript-eslint/scope-manager@8.27.0", "", { "dependencies": { "@typescript-eslint/types": "8.27.0", "@typescript-eslint/visitor-keys": "8.27.0" } }, "sha512-8oI9GwPMQmBryaaxG1tOZdxXVeMDte6NyJA4i7/TWa4fBwgnAXYlIQP+uYOeqAaLJ2JRxlG9CAyL+C+YE9Xknw=="], + "@typescript-eslint/scope-manager": ["@typescript-eslint/scope-manager@8.29.0", "", { "dependencies": { "@typescript-eslint/types": "8.29.0", "@typescript-eslint/visitor-keys": "8.29.0" } }, "sha512-aO1PVsq7Gm+tcghabUpzEnVSFMCU4/nYIgC2GOatJcllvWfnhrgW0ZEbnTxm36QsikmCN1K/6ZgM7fok2I7xNw=="], - "@typescript-eslint/type-utils": ["@typescript-eslint/type-utils@8.27.0", "", { "dependencies": { "@typescript-eslint/typescript-estree": "8.27.0", "@typescript-eslint/utils": "8.27.0", "debug": "^4.3.4", "ts-api-utils": "^2.0.1" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-wVArTVcz1oJOIEJxui/nRhV0TXzD/zMSOYi/ggCfNq78EIszddXcJb7r4RCp/oBrjt8n9A0BSxRMKxHftpDxDA=="], + "@typescript-eslint/type-utils": ["@typescript-eslint/type-utils@8.29.0", "", { "dependencies": { "@typescript-eslint/typescript-estree": "8.29.0", "@typescript-eslint/utils": "8.29.0", "debug": "^4.3.4", "ts-api-utils": "^2.0.1" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-ahaWQ42JAOx+NKEf5++WC/ua17q5l+j1GFrbbpVKzFL/tKVc0aYY8rVSYUpUvt2hUP1YBr7mwXzx+E/DfUWI9Q=="], - "@typescript-eslint/types": ["@typescript-eslint/types@8.27.0", "", {}, "sha512-/6cp9yL72yUHAYq9g6DsAU+vVfvQmd1a8KyA81uvfDE21O2DwQ/qxlM4AR8TSdAu+kJLBDrEHKC5/W2/nxsY0A=="], + "@typescript-eslint/types": ["@typescript-eslint/types@8.29.0", "", {}, "sha512-wcJL/+cOXV+RE3gjCyl/V2G877+2faqvlgtso/ZRbTCnZazh0gXhe+7gbAnfubzN2bNsBtZjDvlh7ero8uIbzg=="], - "@typescript-eslint/typescript-estree": ["@typescript-eslint/typescript-estree@8.27.0", "", { "dependencies": { "@typescript-eslint/types": "8.27.0", "@typescript-eslint/visitor-keys": "8.27.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", "ts-api-utils": "^2.0.1" }, "peerDependencies": { "typescript": ">=4.8.4 <5.9.0" } }, "sha512-BnKq8cqPVoMw71O38a1tEb6iebEgGA80icSxW7g+kndx0o6ot6696HjG7NdgfuAVmVEtwXUr3L8R9ZuVjoQL6A=="], + "@typescript-eslint/typescript-estree": ["@typescript-eslint/typescript-estree@8.29.0", "", { "dependencies": { "@typescript-eslint/types": "8.29.0", "@typescript-eslint/visitor-keys": "8.29.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", "ts-api-utils": "^2.0.1" }, "peerDependencies": { "typescript": ">=4.8.4 <5.9.0" } }, "sha512-yOfen3jE9ISZR/hHpU/bmNvTtBW1NjRbkSFdZOksL1N+ybPEE7UVGMwqvS6CP022Rp00Sb0tdiIkhSCe6NI8ow=="], - "@typescript-eslint/utils": ["@typescript-eslint/utils@8.27.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@typescript-eslint/scope-manager": "8.27.0", "@typescript-eslint/types": "8.27.0", "@typescript-eslint/typescript-estree": "8.27.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-njkodcwH1yvmo31YWgRHNb/x1Xhhq4/m81PhtvmRngD8iHPehxffz1SNCO+kwaePhATC+kOa/ggmvPoPza5i0Q=="], + "@typescript-eslint/utils": ["@typescript-eslint/utils@8.29.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@typescript-eslint/scope-manager": "8.29.0", "@typescript-eslint/types": "8.29.0", "@typescript-eslint/typescript-estree": "8.29.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-gX/A0Mz9Bskm8avSWFcK0gP7cZpbY4AIo6B0hWYFCaIsz750oaiWR4Jr2CI+PQhfW1CpcQr9OlfPS+kMFegjXA=="], - "@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.27.0", "", { "dependencies": { "@typescript-eslint/types": "8.27.0", "eslint-visitor-keys": "^4.2.0" } }, "sha512-WsXQwMkILJvffP6z4U3FYJPlbf/j07HIxmDjZpbNvBJkMfvwXj5ACRkkHwBDvLBbDbtX5TdU64/rcvKJ/vuInQ=="], + "@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.29.0", "", { "dependencies": { "@typescript-eslint/types": "8.29.0", "eslint-visitor-keys": "^4.2.0" } }, "sha512-Sne/pVz8ryR03NFK21VpN88dZ2FdQXOlq3VIklbrTYEt8yXtRFr9tvUhqvCeKjqYk5FSim37sHbooT6vzBTZcg=="], "acorn": ["acorn@8.14.1", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg=="], @@ -333,7 +333,7 @@ "braces": ["braces@3.0.3", "", { "dependencies": { "fill-range": "^7.1.1" } }, "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA=="], - "bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="], + "bun-types": ["bun-types@1.2.8", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-D5npfxKIGuYe9dTHLK1hi4XFmbMdKYoLrgyd25rrUyCrnyU4ljmQW7vDdonvibKeyU72mZuixIhQ2J+q6uM0Mg=="], "callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="], @@ -375,7 +375,7 @@ "eslint-config-prettier": ["eslint-config-prettier@9.1.0", "", { "peerDependencies": { "eslint": ">=7.0.0" }, "bin": { "eslint-config-prettier": "bin/cli.js" } }, "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw=="], - "eslint-plugin-prettier": ["eslint-plugin-prettier@5.2.4", "", { "dependencies": { "prettier-linter-helpers": "^1.0.0", "synckit": "^0.10.2" }, "peerDependencies": { "@types/eslint": ">=8.0.0", "eslint": ">=8.0.0", "eslint-config-prettier": "*", "prettier": ">=3.0.0" }, "optionalPeers": ["@types/eslint", "eslint-config-prettier"] }, "sha512-SFtuYmnhwYCtuCDTKPoK+CEzCnEgKTU2qTLwoCxvrC0MFBTIXo1i6hDYOI4cwHaE5GZtlWmTN3YfucYi7KJwPw=="], + "eslint-plugin-prettier": ["eslint-plugin-prettier@5.2.5", "", { "dependencies": { "prettier-linter-helpers": "^1.0.0", "synckit": "^0.10.2" }, "peerDependencies": { "@types/eslint": ">=8.0.0", "eslint": ">=8.0.0", "eslint-config-prettier": ">= 7.0.0 <10.0.0 || >=10.1.0", "prettier": ">=3.0.0" }, "optionalPeers": ["@types/eslint", "eslint-config-prettier"] }, "sha512-IKKP8R87pJyMl7WWamLgPkloB16dagPIdd2FjBDbyRYPKo93wS/NbCOPh6gH+ieNLC+XZrhJt/kWj0PS/DFdmg=="], "eslint-scope": ["eslint-scope@8.3.0", "", { "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "sha512-pUNxi75F8MJ/GdeKtVLSbYg4ZI34J6C0C7sbL4YOp2exGwen7ZsuBqKzUhXd0qMQ362yET3z+uPwKeg/0C2XCQ=="], @@ -549,7 +549,7 @@ "typescript": ["typescript@5.8.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ=="], - "typescript-eslint": ["typescript-eslint@8.27.0", "", { "dependencies": { "@typescript-eslint/eslint-plugin": "8.27.0", "@typescript-eslint/parser": "8.27.0", "@typescript-eslint/utils": "8.27.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-ZZ/8+Y0rRUMuW1gJaPtLWe4ryHbsPLzzibk5Sq+IFa2aOH1Vo0gPr1fbA6pOnzBke7zC2Da4w8AyCgxKXo3lqA=="], + "typescript-eslint": ["typescript-eslint@8.29.0", "", { "dependencies": { "@typescript-eslint/eslint-plugin": "8.29.0", "@typescript-eslint/parser": "8.29.0", "@typescript-eslint/utils": "8.29.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-ep9rVd9B4kQsZ7ZnWCVxUE/xDLUUUsRzE0poAeNu+4CkFErLfuvPt/qtm2EpnSyfvsR0S6QzDFSrPCFBwf64fg=="], "undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], @@ -569,9 +569,9 @@ "@humanfs/node/@humanwhocodes/retry": ["@humanwhocodes/retry@0.3.1", "", {}, "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA=="], - "@typescript-eslint/typescript-estree/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="], + "@types/bun/bun-types": ["bun-types@1.2.7", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-P4hHhk7kjF99acXqKvltyuMQ2kf/rzIw3ylEDpCxDS9Xa0X0Yp/gJu/vDCucmWpiur5qJ0lwB2bWzOXa2GlHqA=="], - "bun-types/@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], + "@typescript-eslint/typescript-estree/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="], "fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], diff --git a/package.json b/package.json index 5e298dc5c5..6a74f35ee7 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,12 @@ }, "devDependencies": { "@eslint/js": "^9.23.0", - "@types/bun": "^1.2.5", - "bun-types": "^1.2.5", + "@types/bun": "^1.2.8", + "bun-types": "^1.2.8", "eslint": "^9.23.0", "eslint-config-prettier": "^9.1.0", - "eslint-plugin-prettier": "^5.2.4", + "eslint-plugin-prettier": "^5.2.5", "prettier": "^3.5.3", - "typescript-eslint": "^8.27.0" + "typescript-eslint": "^8.29.0" } } diff --git a/packages/client-query/package.json b/packages/client-query/package.json index 430773b9b1..6a96b56d79 100644 --- a/packages/client-query/package.json +++ b/packages/client-query/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-client-query", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.js", "module": "dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/cockroach/migrations/00_schema.sql b/packages/cockroach/migrations/00_schema.sql deleted file mode 100644 index ed4ea1dc0c..0000000000 --- a/packages/cockroach/migrations/00_schema.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE SCHEMA IF NOT EXISTS communication; diff --git a/packages/cockroach/migrations/01_message.sql b/packages/cockroach/migrations/01_message.sql deleted file mode 100644 index 37f45dbef7..0000000000 --- a/packages/cockroach/migrations/01_message.sql +++ /dev/null @@ -1,35 +0,0 @@ -CREATE TABLE IF NOT EXISTS communication.messages -( - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - id INT8 NOT NULL, - - content TEXT NOT NULL, - creator VARCHAR(255) NOT NULL, - created TIMESTAMPTZ NOT NULL, - - type VARCHAR(255) NOT NULL, - data JSONB NOT NULL DEFAULT '{}', - - - PRIMARY KEY (workspace_id, card_id, id) -); - -CREATE INDEX IF NOT EXISTS idx_messages_workspace_card ON communication.messages (workspace_id, card_id); -CREATE INDEX IF NOT EXISTS idx_messages_workspace_card_id ON communication.messages (workspace_id, card_id, id); - -CREATE TABLE IF NOT EXISTS communication.messages_groups -( - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - blob_id UUID NOT NULL, - - from_sec TIMESTAMPTZ(0) NOT NULL, - to_sec TIMESTAMPTZ(0) NOT NULL, - count INT NOT NULL, - - PRIMARY KEY (workspace_id, card_id, blob_id) -); - - -CREATE INDEX IF NOT EXISTS idx_messages_groups_workspace_card ON communication.messages_groups (workspace_id, card_id); \ No newline at end of file diff --git a/packages/cockroach/migrations/02_patch.sql b/packages/cockroach/migrations/02_patch.sql deleted file mode 100644 index 1c2037b046..0000000000 --- a/packages/cockroach/migrations/02_patch.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE IF NOT EXISTS communication.patch -( - id INT8 NOT NULL DEFAULT unique_rowid(), - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - message_id INT8 NOT NULL, - type VARCHAR(255) NOT NULL, - content TEXT NOT NULL, - creator VARCHAR(255) NOT NULL, - created TIMESTAMPTZ NOT NULL, - message_created_sec TIMESTAMPTZ(0) NOT NULL, - - PRIMARY KEY (id) -); - -CREATE INDEX IF NOT EXISTS idx_patch_workspace_card_message ON communication.patch (workspace_id, card_id, message_id); \ No newline at end of file diff --git a/packages/cockroach/migrations/03_files.sql b/packages/cockroach/migrations/03_files.sql deleted file mode 100644 index 0689245041..0000000000 --- a/packages/cockroach/migrations/03_files.sql +++ /dev/null @@ -1,20 +0,0 @@ -CREATE TABLE IF NOT EXISTS communication.files -( - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - message_id INT8 NOT NULL, - - blob_id UUID NOT NULL, - filename VARCHAR(255) NOT NULL, - type VARCHAR(255) NOT NULL, - size INT8 NOT NULL, - - creator VARCHAR(255) NOT NULL, - created TIMESTAMPTZ NOT NULL DEFAULT now(), - - message_created_sec TIMESTAMPTZ(0) NOT NULL, - - PRIMARY KEY (workspace_id, card_id, message_id, blob_id) -); - -CREATE INDEX IF NOT EXISTS files_workspace_card_message_idx ON communication.files (workspace_id, card_id, message_id); diff --git a/packages/cockroach/migrations/04_reaction.sql b/packages/cockroach/migrations/04_reaction.sql deleted file mode 100644 index 30e8ce02a7..0000000000 --- a/packages/cockroach/migrations/04_reaction.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE IF NOT EXISTS communication.reactions -( - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - message_id INT8 NOT NULL, - reaction VARCHAR(100) NOT NULL, - creator VARCHAR(255) NOT NULL, - created TIMESTAMPTZ NOT NULL DEFAULT now(), - - FOREIGN KEY (workspace_id, card_id, message_id) REFERENCES communication.messages (workspace_id, card_id, id) ON DELETE CASCADE, - PRIMARY KEY (workspace_id, card_id, message_id, creator, reaction) -); - -CREATE INDEX IF NOT EXISTS idx_reactions_workspace_card_message ON communication.reactions (workspace_id, card_id, message_id); \ No newline at end of file diff --git a/packages/cockroach/migrations/05_thread.sql b/packages/cockroach/migrations/05_thread.sql deleted file mode 100644 index 73d6e50120..0000000000 --- a/packages/cockroach/migrations/05_thread.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE IF NOT EXISTS communication.thread -( - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - message_id INT8 NOT NULL, - thread_id VARCHAR(255) NOT NULL, - replies_count INT NOT NULL, - last_reply TIMESTAMPTZ NOT NULL, - - PRIMARY KEY (workspace_id, thread_id), - UNIQUE (workspace_id, card_id, message_id) -); - -CREATE INDEX IF NOT EXISTS idx_thread_workspace_card_message ON communication.thread (workspace_id, thread_id); -CREATE INDEX IF NOT EXISTS idx_thread_workspace_card_message ON communication.thread (workspace_id, card_id, message_id); \ No newline at end of file diff --git a/packages/cockroach/migrations/06_notification.sql b/packages/cockroach/migrations/06_notification.sql deleted file mode 100644 index 88d60cd21f..0000000000 --- a/packages/cockroach/migrations/06_notification.sql +++ /dev/null @@ -1,38 +0,0 @@ -CREATE TABLE IF NOT EXISTS communication.notification_context -( - id INT8 NOT NULL DEFAULT unique_rowid(), - - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - account UUID NOT NULL, - - last_view TIMESTAMPTZ NOT NULL DEFAULT now(), - last_update TIMESTAMPTZ NOT NULL DEFAULT now(), - - PRIMARY KEY (id), - UNIQUE (workspace_id, card_id, account) -); - -CREATE TABLE IF NOT EXISTS communication.notifications -( - id INT8 NOT NULL DEFAULT unique_rowid(), - context_id INT8 NOT NULL, - message_id INT8, - created TIMESTAMPTZ NOT NULL, - content JSONB NOT NULL DEFAULT '{}', - - PRIMARY KEY (id), - FOREIGN KEY (context_id) REFERENCES communication.notification_context (id) ON DELETE CASCADE -); - -CREATE INDEX IF NOT EXISTS notification_context_idx ON communication.notifications (context_id); - -CREATE TABLE IF NOT EXISTS communication.collaborators -( - workspace_id UUID NOT NULL, - card_id VARCHAR(255) NOT NULL, - account UUID NOT NULL, - date TIMESTAMPTZ NOT NULL DEFAULT now(), - - PRIMARY KEY (workspace_id, card_id, account) -); \ No newline at end of file diff --git a/packages/cockroach/package.json b/packages/cockroach/package.json index 4971913475..0c0fa78a48 100644 --- a/packages/cockroach/package.json +++ b/packages/cockroach/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-cockroach", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.js", "module": "dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/cockroach/src/adapter.ts b/packages/cockroach/src/adapter.ts index c471d49093..a596d9c81d 100644 --- a/packages/cockroach/src/adapter.ts +++ b/packages/cockroach/src/adapter.ts @@ -46,6 +46,7 @@ import { NotificationsDb } from './db/notification' import { connect, type PostgresClientReference } from './connection' import { type Logger, type Options, type SqlClient, type SqlParams, type SqlRow } from './types' import { injectVars } from './utils' +import { initSchema } from './init' export class CockroachAdapter implements DbAdapter { private readonly message: MessagesDb @@ -204,6 +205,7 @@ export async function createDbAdapter( const greenUrl = process.env.GREEN_URL ?? '' const connection = connect(connectionString) const sql = await connection.getClient() + await initSchema(sql) if (greenUrl !== '') { const client = new GreenClient(greenUrl, sql) diff --git a/packages/cockroach/src/init.ts b/packages/cockroach/src/init.ts new file mode 100644 index 0000000000..528aac3859 --- /dev/null +++ b/packages/cockroach/src/init.ts @@ -0,0 +1,194 @@ +// +// Copyright © 2025 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import type postgres from 'postgres' + +const migrationsTableName = 'communication._migrations' + +export async function initSchema(sql: postgres.Sql) { + console.log('🗃️ Initializing schema...') + await sql.unsafe('CREATE SCHEMA IF NOT EXISTS communication;') + await sql.unsafe(`CREATE TABLE IF NOT EXISTS ${migrationsTableName} + ( + name VARCHAR(255) NOT NULL, + created_on TIMESTAMPTZ NOT NULL DEFAULT now() + )`) + + const appliedMigrations = await sql.unsafe(`SELECT name + FROM ${migrationsTableName}`) + const appliedNames = appliedMigrations.map((it) => it.name) + + const migrations = [migrationO1()] + for (const [name, sqlString] of migrations) { + if (appliedNames.includes(name)) continue + try { + await sql.unsafe(sqlString) + await sql.unsafe( + `INSERT INTO ${migrationsTableName}(name) + VALUES ($1::varchar);`, + [name] + ) + console.log(`✅ Migration ${name} applied`) + } catch (err) { + console.error(`❌ Failed on ${name}:`, err) + throw err + } + } + console.log('🎉 All migrations complete') +} + +function migrationO1(): [string, string] { + const sql = ` + CREATE TABLE IF NOT EXISTS communication.messages + ( + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + id INT8 NOT NULL, + + content TEXT NOT NULL, + creator VARCHAR(255) NOT NULL, + created TIMESTAMPTZ NOT NULL, + + type VARCHAR(255) NOT NULL, + data JSONB NOT NULL DEFAULT '{}', + + + PRIMARY KEY (workspace_id, card_id, id) + ); + + CREATE INDEX IF NOT EXISTS idx_messages_workspace_card ON communication.messages (workspace_id, card_id); + CREATE INDEX IF NOT EXISTS idx_messages_workspace_card_id ON communication.messages (workspace_id, card_id, id); + + CREATE TABLE IF NOT EXISTS communication.messages_groups + ( + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + blob_id UUID NOT NULL, + + from_sec TIMESTAMPTZ(0) NOT NULL, + to_sec TIMESTAMPTZ(0) NOT NULL, + count INT NOT NULL, + + PRIMARY KEY (workspace_id, card_id, blob_id) + ); + + + CREATE INDEX IF NOT EXISTS idx_messages_groups_workspace_card ON communication.messages_groups (workspace_id, card_id); + CREATE TABLE IF NOT EXISTS communication.patch + ( + id INT8 NOT NULL DEFAULT unique_rowid(), + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + message_id INT8 NOT NULL, + type VARCHAR(255) NOT NULL, + content TEXT NOT NULL, + creator VARCHAR(255) NOT NULL, + created TIMESTAMPTZ NOT NULL, + message_created_sec TIMESTAMPTZ(0) NOT NULL, + + PRIMARY KEY (id) + ); + + CREATE INDEX IF NOT EXISTS idx_patch_workspace_card_message ON communication.patch (workspace_id, card_id, message_id); + CREATE TABLE IF NOT EXISTS communication.files + ( + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + message_id INT8 NOT NULL, + + blob_id UUID NOT NULL, + filename VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + size INT8 NOT NULL, + + creator VARCHAR(255) NOT NULL, + created TIMESTAMPTZ NOT NULL DEFAULT now(), + + message_created_sec TIMESTAMPTZ(0) NOT NULL, + + PRIMARY KEY (workspace_id, card_id, message_id, blob_id) + ); + + CREATE INDEX IF NOT EXISTS files_workspace_card_message_idx ON communication.files (workspace_id, card_id, message_id); + CREATE TABLE IF NOT EXISTS communication.reactions + ( + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + message_id INT8 NOT NULL, + reaction VARCHAR(100) NOT NULL, + creator VARCHAR(255) NOT NULL, + created TIMESTAMPTZ NOT NULL DEFAULT now(), + + FOREIGN KEY (workspace_id, card_id, message_id) REFERENCES communication.messages (workspace_id, card_id, id) ON DELETE CASCADE, + PRIMARY KEY (workspace_id, card_id, message_id, creator, reaction) + ); + + CREATE INDEX IF NOT EXISTS idx_reactions_workspace_card_message ON communication.reactions (workspace_id, card_id, message_id); + CREATE TABLE IF NOT EXISTS communication.thread + ( + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + message_id INT8 NOT NULL, + thread_id VARCHAR(255) NOT NULL, + replies_count INT NOT NULL, + last_reply TIMESTAMPTZ NOT NULL, + + PRIMARY KEY (workspace_id, thread_id), + UNIQUE (workspace_id, card_id, message_id) + ); + + CREATE INDEX IF NOT EXISTS idx_thread_workspace_card_message ON communication.thread (workspace_id, thread_id); + CREATE INDEX IF NOT EXISTS idx_thread_workspace_card_message ON communication.thread (workspace_id, card_id, message_id); + CREATE TABLE IF NOT EXISTS communication.notification_context + ( + id INT8 NOT NULL DEFAULT unique_rowid(), + + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + account UUID NOT NULL, + + last_view TIMESTAMPTZ NOT NULL DEFAULT now(), + last_update TIMESTAMPTZ NOT NULL DEFAULT now(), + + PRIMARY KEY (id), + UNIQUE (workspace_id, card_id, account) + ); + + CREATE TABLE IF NOT EXISTS communication.notifications + ( + id INT8 NOT NULL DEFAULT unique_rowid(), + context_id INT8 NOT NULL, + message_id INT8, + created TIMESTAMPTZ NOT NULL, + content JSONB NOT NULL DEFAULT '{}', + + PRIMARY KEY (id), + FOREIGN KEY (context_id) REFERENCES communication.notification_context (id) ON DELETE CASCADE + ); + + CREATE INDEX IF NOT EXISTS notification_context_idx ON communication.notifications (context_id); + + CREATE TABLE IF NOT EXISTS communication.collaborators + ( + workspace_id UUID NOT NULL, + card_id VARCHAR(255) NOT NULL, + account UUID NOT NULL, + date TIMESTAMPTZ NOT NULL DEFAULT now(), + + PRIMARY KEY (workspace_id, card_id, account) + ); + ` + return ['init_tables_01', sql] +} diff --git a/packages/query/package.json b/packages/query/package.json index 0afa492501..7a29f25abb 100644 --- a/packages/query/package.json +++ b/packages/query/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-query", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.js", "module": "dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/rest-client/package.json b/packages/rest-client/package.json index 0ece05e977..8e83956e50 100644 --- a/packages/rest-client/package.json +++ b/packages/rest-client/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-rest-client", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.cjs", "module": "dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/sdk-types/package.json b/packages/sdk-types/package.json index e43b1fd963..5b49f95b68 100644 --- a/packages/sdk-types/package.json +++ b/packages/sdk-types/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-sdk-types", - "version": "0.1.147", + "version": "0.1.150", "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/server/package.json b/packages/server/package.json index 684fb03b52..083cbb46ee 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-server", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.js", "module": "dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/shared/package.json b/packages/shared/package.json index 6ec1fa97bc..4b4af0853f 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-shared", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.cjs", "module": "dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/types/package.json b/packages/types/package.json index 1501b2565d..2ed88f5952 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-types", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.cjs", "module": "dist/index.js", "types": "./types/index.d.ts", diff --git a/packages/yaml/package.json b/packages/yaml/package.json index c97729c12c..fbeb357649 100644 --- a/packages/yaml/package.json +++ b/packages/yaml/package.json @@ -1,6 +1,6 @@ { "name": "@hcengineering/communication-yaml", - "version": "0.1.147", + "version": "0.1.150", "main": "dist/index.cjs", "module": "dist/index.js", "types": "./types/index.d.ts",