@lightupai/polaris 0.0.55 → 0.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,3 +68,28 @@ jobs:
68
68
  # Set version in package.json for this publish only (not committed)
69
69
  npm version "$NEW" --no-git-tag-version
70
70
  npm publish --access public
71
+
72
+ deploy:
73
+ needs: test
74
+ runs-on: ubuntu-latest
75
+ if: github.ref == 'refs/heads/master' && github.event_name == 'push'
76
+ concurrency:
77
+ group: production-deploy
78
+ cancel-in-progress: false
79
+
80
+ steps:
81
+ - name: Deploy to production
82
+ env:
83
+ DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
84
+ run: |
85
+ mkdir -p ~/.ssh
86
+ echo "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key
87
+ chmod 600 ~/.ssh/deploy_key
88
+ ssh-keyscan -H withpolaris.ai >> ~/.ssh/known_hosts
89
+ ssh -i ~/.ssh/deploy_key deploy@withpolaris.ai "
90
+ cd /opt/polaris &&
91
+ git pull --ff-only &&
92
+ docker compose -f docker-compose.prod.yml build &&
93
+ docker compose -f docker-compose.prod.yml up -d --remove-orphans &&
94
+ docker compose -f docker-compose.prod.yml ps
95
+ "
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightupai/polaris",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "polaris": "bin/polaris",
package/src/service/db.ts CHANGED
@@ -34,7 +34,26 @@ export async function createDb(connectionString?: string): Promise<Sql> {
34
34
  return sql;
35
35
  }
36
36
 
37
+ // Arbitrary fixed key for the schema-init advisory lock (issue #117).
38
+ const SCHEMA_LOCK_KEY = 0x504c5253; // "PLRS"
39
+
37
40
  export async function ensureSchema(sql: Sql): Promise<void> {
41
+ // API and web both call this on startup. Serialize concurrent callers with a
42
+ // session-level advisory lock held on a reserved (dedicated) connection, so
43
+ // they don't race on `CREATE TABLE IF NOT EXISTS` — which isn't concurrency
44
+ // safe: two connections can both pass the existence check and then collide on
45
+ // the underlying pg_type creation (issue #117).
46
+ const lock = await sql.reserve();
47
+ try {
48
+ await lock`SELECT pg_advisory_lock(${SCHEMA_LOCK_KEY}::bigint)`;
49
+ await createSchemaTables(sql);
50
+ } finally {
51
+ await lock`SELECT pg_advisory_unlock(${SCHEMA_LOCK_KEY}::bigint)`;
52
+ lock.release();
53
+ }
54
+ }
55
+
56
+ async function createSchemaTables(sql: Sql): Promise<void> {
38
57
  await sql`
39
58
  CREATE TABLE IF NOT EXISTS orgs (
40
59
  id TEXT PRIMARY KEY,