Skip to content

Commit 0dfc7ab

Browse files
committed
fix(projects): correct rollout fixtures and schema-push index
1 parent bcc1011 commit 0dfc7ab

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎apps/sim/lib/projects/__integration__/foundation.integration.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,18 @@ async function fixture(org = true, count = 2) {
207207

208208
/**
209209
* Waits until the operation under test is blocked behind `blockerPid`: a session whose
210-
* current statement contains `waitingIn` (an advisory lock tag or row-lock clause), so an
211-
* unrelated waiter cannot release the barrier early.
210+
* current statement contains `waitingIn` (an advisory lock tag or row-lock clause).
211+
* When the caller owns the transaction, `waitingPid` identifies that exact backend.
212212
*/
213-
async function waitUntilBlockedBy(blockerPid: number, waitingIn: string) {
213+
async function waitUntilBlockedBy(blockerPid: number, waitingIn: string, waitingPid?: number) {
214214
await expect
215215
.poll(
216216
async () =>
217217
(
218218
await db.execute(sql`
219219
SELECT 1 FROM pg_stat_activity
220-
WHERE ${blockerPid} = ANY(pg_blocking_pids(pid))
220+
WHERE ${waitingPid === undefined ? sql`true` : sql`pid = ${waitingPid}`}
221+
AND ${blockerPid} = ANY(pg_blocking_pids(pid))
221222
AND position(${waitingIn.toLowerCase()} in lower(query)) > 0
222223
`)
223224
).length,
@@ -1394,14 +1395,22 @@ describe('Project foundation at the database and application boundary', () => {
13941395
)
13951396
})
13961397
const blocker = await held.promise
1398+
const detachPid = createDeferred<number>()
13971399
const detach = db
1398-
.transaction((tx) => splitForkProject(tx, f.ids[1]))
1400+
.transaction(async (tx) => {
1401+
const [backend] = await tx.execute<{ pid: number }>(sql`SELECT pg_backend_pid() AS pid`)
1402+
detachPid.resolve(backend.pid)
1403+
return splitForkProject(tx, f.ids[1])
1404+
})
13991405
.then(
14001406
() => null,
1401-
(error: unknown) => error
1407+
(error: unknown) => {
1408+
detachPid.reject(error)
1409+
return error
1410+
}
14021411
)
14031412
try {
1404-
await waitUntilBlockedBy(blocker, "lock='project'")
1413+
await waitUntilBlockedBy(blocker, "lock='project'", await detachPid.promise)
14051414
} finally {
14061415
release.resolve()
14071416
await legacy

‎apps/sim/lib/workspaces/organization-workspaces.integration.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ beforeAll(async () => {
4343
CREATE TABLE workspace (
4444
id text PRIMARY KEY, name text, owner_id text, organization_id text, workspace_mode text,
4545
project_id text NOT NULL REFERENCES project(id) ON DELETE RESTRICT,
46+
forked_from_workspace_id text,
4647
billed_account_user_id text, allow_personal_api_keys boolean DEFAULT true,
4748
archived_at timestamp, organization_assigned_at timestamp, updated_at timestamp,
4849
storage_used_bytes bigint NOT NULL
4950
);
51+
CREATE TABLE project_workspace (
52+
project_id text NOT NULL REFERENCES project(id) ON DELETE RESTRICT,
53+
workspace_id text NOT NULL UNIQUE REFERENCES workspace(id) ON DELETE CASCADE,
54+
PRIMARY KEY (project_id, workspace_id)
55+
);
5056
CREATE TABLE permissions (
5157
id text PRIMARY KEY, user_id text, entity_type text, entity_id text, permission_type text,
5258
created_at timestamp, updated_at timestamp, UNIQUE(user_id, entity_type, entity_id)
@@ -64,7 +70,7 @@ beforeAll(async () => {
6470

6571
beforeEach(async () => {
6672
await connection.unsafe(`
67-
TRUNCATE member, organization, project, permission_group, invitation, user_stats, workspace, permissions,
73+
TRUNCATE member, organization, project, project_workspace, permission_group, invitation, user_stats, workspace, permissions,
6874
workspace_files, knowledge_base, document, knowledge_connector;
6975
INSERT INTO member VALUES ('owner-membership', 'org', 'org-owner', 'owner');
7076
INSERT INTO organization VALUES ('org', 40);

‎packages/db/migrations/meta/0404_snapshot.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27101,7 +27101,7 @@
2710127101
}
2710227102
],
2710327103
"isUnique": false,
27104-
"concurrently": false,
27104+
"concurrently": true,
2710527105
"method": "btree",
2710627106
"with": {}
2710727107
},

‎packages/db/schema.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ export const workspace = pgTable(
20612061
(table) => ({
20622062
ownerIdIdx: index('workspace_owner_id_idx').on(table.ownerId),
20632063
organizationIdIdx: index('workspace_organization_id_idx').on(table.organizationId),
2064-
projectIdIdx: index('workspace_project_id_id_idx').on(table.projectId, table.id),
2064+
projectIdIdx: index('workspace_project_id_id_idx').on(table.projectId, table.id).concurrently(),
20652065
nonNegativeStorage: check(
20662066
'workspace_storage_used_bytes_non_negative',
20672067
sql`${table.storageUsedBytes} >= 0`

‎packages/db/scripts/push.integration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export const knowledgeBases = pgTable('knowledge_base', {
195195
await schema(`export const projects = pgTable('project', { id: text('id').primaryKey() })
196196
export const workspaces = pgTable('workspace', {
197197
id: text('id').primaryKey(), forkedFromWorkspaceId: text('forked_from_workspace_id'), projectId: text('project_id'),
198-
}, (table) => [index('workspace_project_id_id_idx').on(table.projectId, table.id)])
198+
}, (table) => [index('workspace_project_id_id_idx').on(table.projectId, table.id).concurrently()])
199199
export const memberships = pgTable('project_workspace', {
200200
projectId: text('project_id').notNull(), workspaceId: text('workspace_id').notNull().unique(),
201201
})`)

0 commit comments

Comments
 (0)