From e667345caf89dfe09520f7ef031d728bcefe5966 Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Tue, 2 Dec 2025 09:04:07 +0800 Subject: [PATCH] feat: support alter table replica identity in pg --- pegjs/postgresql.pegjs | 20 ++++++++++++++++++++ test/postgres.spec.js | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/pegjs/postgresql.pegjs b/pegjs/postgresql.pegjs index 7aed8e90..7bfb3e8a 100644 --- a/pegjs/postgresql.pegjs +++ b/pegjs/postgresql.pegjs @@ -1901,6 +1901,7 @@ alter_action / ALTER_COLUMN_DATA_TYPE / ALTER_COLUMN_DEFAULT / ALTER_COLUMN_NOT_NULL + / ALTER_REPLICA_IDENTITY ALTER_ADD_COLUMN = KW_ADD __ @@ -2162,6 +2163,25 @@ ALTER_COLUMN_NOT_NULL type: 'alter', } } + +ALTER_REPLICA_IDENTITY + = 'REPLICA'i __ 'IDENTITY'i __ n:('DEFAULT'i / 'FULL'i / 'NOTHING'i) { + /* => { + action: 'replica'; + keyword?: 'identity'; + resource: 'replica_identity'; + type: 'alter'; + replica_identity: 'default' | 'full' | 'nothing'; + } + */ + return { + action: 'replica', + keyword: 'identity', + resource: 'replica_identity', + replica_identity: n, + type: 'alter', + } + } create_index_definition = kc:(KW_INDEX / KW_KEY) __ c:column? __ diff --git a/test/postgres.spec.js b/test/postgres.spec.js index 6a9f9c8b..000ef4c7 100644 --- a/test/postgres.spec.js +++ b/test/postgres.spec.js @@ -1943,6 +1943,13 @@ describe('Postgres', () => { 'ALTER TABLE "configuration" ADD CONSTRAINT "configuration_pk" PRIMARY KEY ("something", "something_else", "something_something_else")', ] }, + { + title: 'alter replica identity', + sql: [ + 'ALTER TABLE "table_name" REPLICA IDENTITY FULL;', + 'ALTER TABLE "table_name" REPLICA IDENTITY FULL', + ] + }, ] function neatlyNestTestedSQL(sqlList){ sqlList.forEach(sqlInfo => {