Skip to content

Commit 455e496

Browse files
committed
use new column to store migrated config, use new column
1 parent ba02b75 commit 455e496

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

packages/migrations/src/actions/2025.03.26T00-00-00.graphql-eslint.v4.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export default {
2424
name: '2025.03.26T00-00-00.graphql-eslint.v4.ts',
2525
noTransaction: true,
2626
run: async ({ sql, connection }) => {
27+
console.log('Preparing policy config table with a new column (config_v4)...');
28+
await connection.query(
29+
sql`ALTER TABLE
30+
schema_policy_config
31+
ADD COLUMN IF NOT EXISTS "config_v4" jsonb`,
32+
);
33+
2734
console.log('Looking for existing schema_policy_config objects...');
2835

2936
const existingV3Configs = await connection.query(
@@ -50,7 +57,7 @@ export default {
5057
const v4Config = migrateConfig(jsonConfig);
5158

5259
await connection.query(
53-
sql`UPDATE schema_policy_config SET config = ${sql.json(v4Config)} WHERE resource_type = ${resourceType} AND resource_id = ${resourceId}`,
60+
sql`UPDATE schema_policy_config SET config_v4 = ${sql.json(v4Config)} WHERE resource_type = ${resourceType} AND resource_id = ${resourceId}`,
5461
);
5562
console.log(`Migrated config for ${resourceType}:${resourceId}`);
5663
} else {

packages/migrations/test/2025.03.26T00-00-00.policy-eslint-v4-upgrade.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ await describe('migration: policy upgrade: graphql-eslint v3 -> v4', async () =>
246246
await runTo('2025.03.26T00-00-00.graphql-eslint.v4.ts');
247247

248248
// assert scopes are still in place and identical
249-
const newRecord = await db.oneFirst(sql`
250-
SELECT config FROM schema_policy_config WHERE resource_id = ${organization.id}`);
249+
const newRecord = await db.one(sql`
250+
SELECT config, config_v4 FROM schema_policy_config WHERE resource_id = ${organization.id}`);
251251

252-
assert.deepStrictEqual(newRecord, testCase.out);
252+
assert.deepStrictEqual(newRecord.config, testCase.in);
253+
assert.deepStrictEqual(newRecord.config_v4, testCase.out);
253254

254255
await complete();
255256
} finally {

packages/services/storage/src/db/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export interface schema_log {
310310
export interface schema_policy_config {
311311
allow_overriding: boolean;
312312
config: any;
313+
config_v4: any | null;
313314
created_at: Date;
314315
resource_id: string;
315316
resource_type: schema_policy_resource;

packages/services/storage/src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export async function createStorage(
153153
function transformSchemaPolicy(schema_policy: schema_policy_config): SchemaPolicy {
154154
return {
155155
id: `${schema_policy.resource_type}_${schema_policy.resource_id}`,
156-
config: schema_policy.config,
156+
config: schema_policy.config_v4,
157157
createdAt: schema_policy.created_at,
158158
updatedAt: schema_policy.updated_at,
159159
resource: schema_policy.resource_type,
@@ -3416,14 +3416,14 @@ export async function createStorage(
34163416
async setSchemaPolicyForOrganization(input): Promise<SchemaPolicy> {
34173417
const result = await pool.one<schema_policy_config>(sql`/* setSchemaPolicyForOrganization */
34183418
INSERT INTO "schema_policy_config"
3419-
("resource_type", "resource_id", "config", "allow_overriding")
3419+
("resource_type", "resource_id", "config_v4", "allow_overriding")
34203420
VALUES ('ORGANIZATION', ${input.organizationId}, ${sql.jsonb(input.policy)}, ${
34213421
input.allowOverrides
34223422
})
34233423
ON CONFLICT
34243424
(resource_type, resource_id)
34253425
DO UPDATE
3426-
SET "config" = ${sql.jsonb(input.policy)},
3426+
SET "config_v4" = ${sql.jsonb(input.policy)},
34273427
"allow_overriding" = ${input.allowOverrides},
34283428
"updated_at" = now()
34293429
RETURNING *;
@@ -3434,12 +3434,12 @@ export async function createStorage(
34343434
async setSchemaPolicyForProject(input): Promise<SchemaPolicy> {
34353435
const result = await pool.one<schema_policy_config>(sql`/* setSchemaPolicyForProject */
34363436
INSERT INTO "schema_policy_config"
3437-
("resource_type", "resource_id", "config")
3437+
("resource_type", "resource_id", "config_v4")
34383438
VALUES ('PROJECT', ${input.projectId}, ${sql.jsonb(input.policy)})
34393439
ON CONFLICT
34403440
(resource_type, resource_id)
34413441
DO UPDATE
3442-
SET "config" = ${sql.jsonb(input.policy)},
3442+
SET "config_v4" = ${sql.jsonb(input.policy)},
34433443
"updated_at" = now()
34443444
RETURNING *;
34453445
`);

pnpm-lock.yaml

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)