1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Refactor "ALTER some-obj SET SCHEMA" implementation

Instead of having each object type implement the catalog munging
independently, centralize knowledge about how to do it and expand the
existing table in objectaddress.c with enough data about each object
type to support this operation.

Author: KaiGai Kohei
Tweaks by me
Reviewed by Robert Haas
This commit is contained in:
Alvaro Herrera
2012-09-27 18:13:09 -03:00
parent a563d94180
commit 2164f9a125
17 changed files with 321 additions and 557 deletions

View File

@ -346,52 +346,6 @@ RenameTSParser(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH PARSER any_name SET SCHEMA name
*/
void
AlterTSParserNamespace(List *name, const char *newschema)
{
Oid prsId,
nspOid;
Relation rel;
rel = heap_open(TSParserRelationId, RowExclusiveLock);
prsId = get_ts_parser_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSPARSEROID, TSPARSERNAMENSP,
prsId, nspOid,
Anum_pg_ts_parser_prsname,
Anum_pg_ts_parser_prsnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSParserNamespace_oid(Oid prsId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSParserRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSPARSEROID, TSPARSERNAMENSP,
prsId, newNspOid,
Anum_pg_ts_parser_prsname,
Anum_pg_ts_parser_prsnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/* ---------------------- TS Dictionary commands -----------------------*/
/*
@ -625,54 +579,6 @@ RenameTSDictionary(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH DICTIONARY any_name SET SCHEMA name
*/
void
AlterTSDictionaryNamespace(List *name, const char *newschema)
{
Oid dictId,
nspOid;
Relation rel;
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
dictId = get_ts_dict_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSDICTOID, TSDICTNAMENSP,
dictId, nspOid,
Anum_pg_ts_dict_dictname,
Anum_pg_ts_dict_dictnamespace,
Anum_pg_ts_dict_dictowner,
ACL_KIND_TSDICTIONARY);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSDictionaryNamespace_oid(Oid dictId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSDICTOID, TSDICTNAMENSP,
dictId, newNspOid,
Anum_pg_ts_dict_dictname,
Anum_pg_ts_dict_dictnamespace,
Anum_pg_ts_dict_dictowner,
ACL_KIND_TSDICTIONARY);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/*
* Guts of TS dictionary deletion.
*/
@ -1090,52 +996,6 @@ RenameTSTemplate(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH TEMPLATE any_name SET SCHEMA name
*/
void
AlterTSTemplateNamespace(List *name, const char *newschema)
{
Oid tmplId,
nspOid;
Relation rel;
rel = heap_open(TSTemplateRelationId, RowExclusiveLock);
tmplId = get_ts_template_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSTEMPLATEOID, TSTEMPLATENAMENSP,
tmplId, nspOid,
Anum_pg_ts_template_tmplname,
Anum_pg_ts_template_tmplnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSTemplateNamespace_oid(Oid tmplId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSTemplateRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSTEMPLATEOID, TSTEMPLATENAMENSP,
tmplId, newNspOid,
Anum_pg_ts_template_tmplname,
Anum_pg_ts_template_tmplnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/*
* Guts of TS template deletion.
*/
@ -1482,54 +1342,6 @@ RenameTSConfiguration(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH CONFIGURATION any_name SET SCHEMA name
*/
void
AlterTSConfigurationNamespace(List *name, const char *newschema)
{
Oid cfgId,
nspOid;
Relation rel;
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
cfgId = get_ts_config_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSCONFIGOID, TSCONFIGNAMENSP,
cfgId, nspOid,
Anum_pg_ts_config_cfgname,
Anum_pg_ts_config_cfgnamespace,
Anum_pg_ts_config_cfgowner,
ACL_KIND_TSCONFIGURATION);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSConfigurationNamespace_oid(Oid cfgId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSCONFIGOID, TSCONFIGNAMENSP,
cfgId, newNspOid,
Anum_pg_ts_config_cfgname,
Anum_pg_ts_config_cfgnamespace,
Anum_pg_ts_config_cfgowner,
ACL_KIND_TSCONFIGURATION);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/*
* Guts of TS configuration deletion.
*/