From 0a73faa4e2993f811d315a83cd9d7e9e1b0bb8ee Mon Sep 17 00:00:00 2001 From: Claire Neveu Date: Wed, 15 May 2024 16:25:22 -0400 Subject: [PATCH] Add more PG AST nodes --- .../src/ast/schema-manipulation.ts | 123 +++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/packages/sij-dialect-postgresql/src/ast/schema-manipulation.ts b/packages/sij-dialect-postgresql/src/ast/schema-manipulation.ts index 337725e..b74ad5b 100644 --- a/packages/sij-dialect-postgresql/src/ast/schema-manipulation.ts +++ b/packages/sij-dialect-postgresql/src/ast/schema-manipulation.ts @@ -40,7 +40,10 @@ type PgSchemaManipulation = // | AlterTable | AlterTablespace | AlterTextSearchConfiguration - | AlterTextSearchDictionary; + | AlterTextSearchDictionary + | AlterTextSearchParser + | AlterTextSearchTemplate + | AlterType; type UserSpec = Ident | 'CurrentRole' | 'CurrentUser' | 'SessionUser'; @@ -1732,6 +1735,121 @@ interface SetSearchDictionaryOption extends Tagged<'SetSearchDictionaryOption', }> {} const SetSearchDictionaryOption = (args: UnTag): SetSearchDictionaryOption => tag('SetSearchDictionaryOption', args); +/* +ALTER TEXT SEARCH PARSER name RENAME TO new_name +ALTER TEXT SEARCH PARSER name SET SCHEMA new_schema +*/ +interface AlterTextSearchParser extends Tagged<'AlterTextSearchParser', { + readonly name: Ident, + readonly action: Rename | SetSchema +}> {} +const AlterTextSearchParser = (args: UnTag): AlterTextSearchParser => tag('AlterTextSearchParser', args); + +/* +ALTER TEXT SEARCH TEMPLATE name RENAME TO new_name +ALTER TEXT SEARCH TEMPLATE name SET SCHEMA new_schema +*/ +interface AlterTextSearchTemplate extends Tagged<'AlterTextSearchTemplate', { + readonly name: Ident; + readonly action: Rename | OwnerTo +}> {} +const AlterTextSearchTemplate = (args: UnTag): AlterTextSearchTemplate => tag('AlterTextSearchTemplate ', args); + +/* +ALTER TRIGGER name ON table_name RENAME TO new_name +ALTER TRIGGER name ON table_name [ NO ] DEPENDS ON EXTENSION extension_name +*/ +interface AlterTrigger extends Tagged<'AlterTrigger', { + readonly name: Ident; + readonly table: Ident; + readonly action: Rename | DependsOnExtension +}> {} +const AlterTrigger = (args: UnTag): AlterTrigger => tag('AlterTrigger', args); + +/* +ALTER TYPE name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } +ALTER TYPE name RENAME TO new_name +ALTER TYPE name SET SCHEMA new_schema +ALTER TYPE name RENAME ATTRIBUTE attribute_name TO new_attribute_name [ CASCADE | RESTRICT ] +ALTER TYPE name action [, ... ] +ALTER TYPE name ADD VALUE [ IF NOT EXISTS ] new_enum_value [ { BEFORE | AFTER } neighbor_enum_value ] +ALTER TYPE name RENAME VALUE existing_enum_value TO new_enum_value +ALTER TYPE name SET ( property = value [, ... ] ) + +where action is one of: + + ADD ATTRIBUTE attribute_name data_type [ COLLATE collation ] [ CASCADE | RESTRICT ] + DROP ATTRIBUTE [ IF EXISTS ] attribute_name [ CASCADE | RESTRICT ] + ALTER ATTRIBUTE attribute_name [ SET DATA ] TYPE data_type [ COLLATE collation ] [ CASCADE | RESTRICT ] + +CASCADE | RESTRICT defaults to RESTRICT +*/ +interface AlterType extends Tagged<'AlterType', { + readonly name: Ident; + readonly action: AlterTypeAction +}> {} +const AlterType = (args: UnTag): AlterType => tag('AlterType', args); + +type AlterTypeAction = +| OwnerTo +| Rename +| SetSchema +| RenameAttribute +| Array +| AddValue +| Rename +| SetProperty + +interface RenameAttribute extends Tagged<'RenameAttribute', { + readonly name: Ident + readonly newName: Ident + readonly cascade: boolean, +}> {} +const RenameAttribute = (args: UnTag): RenameAttribute => tag('RenameAttribute', args); + +interface AlterAttribute extends Tagged<'AlterAttribute', { + readonly name: Ident, + readonly type: DataType + readonly cascade: boolean, + readonly collation: Ident, +}> {} +const AlterAttribute = (args: UnTag): AlterAttribute => tag('AlterAttribute', args); + +interface DropAttribute extends Tagged<'DropAttribute', { + readonly name: Ident, + readonly ifExists: boolean, + readonly cascade: boolean, +}> {} +const DropAttribute = (args: UnTag): DropAttribute => tag('DropAttribute', args); + +interface AddAttribute extends Tagged<'AddAttribute', { + readonly name: Ident, + readonly type: DataType + readonly cascade: boolean, +}> {} +const AddAttribute = (args: UnTag): AddAttribute => tag('AddAttribute', args); + +//ALTER TYPE name ADD VALUE [ IF NOT EXISTS ] new_enum_value [ { BEFORE | AFTER } neighbor_enum_value ] +interface AddValue extends Tagged<'AddValue', { + readonly name: Ident, + readonly ifNotExists: boolean, + readonly newValue: StringLit, + readonly neighbor: ['Before' | 'After', StringLit], +}> {} +const AddValue = (args: UnTag): AddValue => tag('AddValue', args); + +interface SetProperty extends Tagged<'SetProperty', { + readonly receive?: Ident | null + readonly send?: Ident | null + readonly typmodIn?: Ident | null + readonly typmodOut?: Ident | null + readonly analyze?: Ident | null + readonly subscript?: Ident | null + readonly storage?: 'Plain' | 'Extended' | 'External' | 'Main' +}> {} +const SetProperty = (args: UnTag): SetProperty => tag('SetProperty', args); + + export { PgSchemaManipulation, Abort, @@ -1777,4 +1895,7 @@ export { AlterTablespace, AlterTextSearchConfiguration, AlterTextSearchDictionary, + AlterTextSearchParser, + AlterTextSearchTemplate, + AlterType, };