Skip to content

Commit ab463ea

Browse files
committed
use new column to store migrated config, use new column
1 parent 99b6662 commit ab463ea

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
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

+1-1
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 || schema_policy.config,
157157
createdAt: schema_policy.created_at,
158158
updatedAt: schema_policy.updated_at,
159159
resource: schema_policy.resource_type,

0 commit comments

Comments
 (0)