Fixes review issues

pull/7253/head
gindibay 2023-11-13 12:07:40 +03:00
parent e31ca6e31e
commit a35cae0ed7
3 changed files with 26 additions and 24 deletions

View File

@ -215,8 +215,8 @@ PreprocessAlterDatabaseStmt(Node *node, const char *queryString,
char *sql = DeparseTreeNode((Node *) stmt); char *sql = DeparseTreeNode((Node *) stmt);
List *commands = list_make3(DISABLE_DDL_PROPAGATION, List *commands = list_make3(DISABLE_DDL_PROPAGATION,
sql, sql,
ENABLE_DDL_PROPAGATION); ENABLE_DDL_PROPAGATION);
if (isSetTablespaceStatement(stmt)) if (isSetTablespaceStatement(stmt))
{ {
@ -231,7 +231,6 @@ PreprocessAlterDatabaseStmt(Node *node, const char *queryString,
{ {
return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
} }
} }
@ -273,7 +272,7 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString,
* PreprocessAlterDatabaseRenameStmt is executed before the statement is applied to the local * PreprocessAlterDatabaseRenameStmt is executed before the statement is applied to the local
* postgres instance. In this stage we prepare ALTER DATABASE RENAME statement to be run on * postgres instance. In this stage we prepare ALTER DATABASE RENAME statement to be run on
* all workers. * all workers.
*/ */
List * List *
PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString, PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext) ProcessUtilityContext processUtilityContext)
@ -631,55 +630,61 @@ GenerateCreateDatabaseStatementFromPgDatabase(Form_pg_database databaseForm)
initStringInfo(&str); initStringInfo(&str);
appendStringInfo(&str, "CREATE DATABASE %s", appendStringInfo(&str, "CREATE DATABASE %s",
quote_identifier(NameStr(databaseForm->datname))); quote_identifier(NameStr(databaseForm->datname)));
if (databaseForm->datdba != InvalidOid) if (databaseForm->datdba != InvalidOid)
{ {
appendStringInfo(&str, " OWNER = %s", appendStringInfo(&str, " OWNER = %s",
quote_literal_cstr(GetUserNameFromId(databaseForm->datdba,false))); quote_literal_cstr(GetUserNameFromId(databaseForm->datdba,
false)));
} }
if (databaseForm->encoding != -1) if (databaseForm->encoding != -1)
{ {
appendStringInfo(&str, " ENCODING = %s", appendStringInfo(&str, " ENCODING = %s",
quote_literal_cstr(pg_encoding_to_char(databaseForm->encoding))); quote_literal_cstr(pg_encoding_to_char(databaseForm->encoding)));
} }
if (collInfo.collation != NULL) if (collInfo.collation != NULL)
{ {
appendStringInfo(&str, " LC_COLLATE = %s", quote_literal_cstr(collInfo.collation)); appendStringInfo(&str, " LC_COLLATE = %s", quote_literal_cstr(
collInfo.collation));
} }
if (collInfo.ctype != NULL) if (collInfo.ctype != NULL)
{ {
appendStringInfo(&str, " LC_CTYPE = %s", quote_literal_cstr(collInfo.ctype)); appendStringInfo(&str, " LC_CTYPE = %s", quote_literal_cstr(collInfo.ctype));
} }
#if PG_VERSION_NUM >= PG_VERSION_15 #if PG_VERSION_NUM >= PG_VERSION_15
if (collInfo.icu_locale != NULL) if (collInfo.icu_locale != NULL)
{ {
appendStringInfo(&str, " ICU_LOCALE = %s", quote_literal_cstr(collInfo.icu_locale)); appendStringInfo(&str, " ICU_LOCALE = %s", quote_literal_cstr(
collInfo.icu_locale));
} }
if (databaseForm->datlocprovider != 0) if (databaseForm->datlocprovider != 0)
{ {
appendStringInfo(&str, " LOCALE_PROVIDER = %s", appendStringInfo(&str, " LOCALE_PROVIDER = %s",
quote_literal_cstr(GetLocaleProviderString(databaseForm->datlocprovider))); quote_literal_cstr(GetLocaleProviderString(
databaseForm->datlocprovider)));
} }
if (collInfo.collversion != NULL) if (collInfo.collversion != NULL)
{ {
appendStringInfo(&str, " COLLATION_VERSION = %s", quote_literal_cstr(collInfo.collversion)); appendStringInfo(&str, " COLLATION_VERSION = %s", quote_literal_cstr(
collInfo.collversion));
} }
#endif #endif
if (databaseForm->dattablespace != InvalidOid) if (databaseForm->dattablespace != InvalidOid)
{ {
appendStringInfo(&str, " TABLESPACE = %s", appendStringInfo(&str, " TABLESPACE = %s",
quote_identifier(GetTablespaceName(databaseForm->dattablespace))); quote_identifier(GetTablespaceName(
databaseForm->dattablespace)));
} }
appendStringInfo(&str, " ALLOW_CONNECTIONS = %s", appendStringInfo(&str, " ALLOW_CONNECTIONS = %s",
quote_literal_cstr(databaseForm->datallowconn ?"true" : "false")); quote_literal_cstr(databaseForm->datallowconn ? "true" : "false"));
if (databaseForm->datconnlimit >= 0) if (databaseForm->datconnlimit >= 0)
{ {
@ -687,7 +692,7 @@ GenerateCreateDatabaseStatementFromPgDatabase(Form_pg_database databaseForm)
} }
appendStringInfo(&str, " IS_TEMPLATE = %s", appendStringInfo(&str, " IS_TEMPLATE = %s",
quote_literal_cstr(databaseForm->datistemplate ? "true" :"false")); quote_literal_cstr(databaseForm->datistemplate ? "true" : "false"));
FreeDatabaseCollationInfo(collInfo); FreeDatabaseCollationInfo(collInfo);

View File

@ -149,7 +149,7 @@ AppendBasicAlterDatabaseOptions(StringInfo buf, DefElem *def, bool
prefix_appended_for_basic_options = true; prefix_appended_for_basic_options = true;
} }
DefElemOptionToStatement(buf, def, alter_database_option_formats, lengthof( DefElemOptionToStatement(buf, def, alter_database_option_formats, lengthof(
alter_database_option_formats)); alter_database_option_formats));
return prefix_appended_for_basic_options; return prefix_appended_for_basic_options;
} }
@ -290,20 +290,19 @@ DeparseAlterDatabaseSetStmt(Node *node)
static void static void
ValidateCreateDatabaseOptions(DefElem *option) ValidateCreateDatabaseOptions(DefElem *option)
{ {
if (strcmp(option->defname, "strategy") == 0){ if (strcmp(option->defname, "strategy") == 0)
{
ereport(ERROR, ereport(ERROR,
errmsg("CREATE DATABASE option \"%s\" is not supported", errmsg("CREATE DATABASE option \"%s\" is not supported",
option->defname)); option->defname));
} }
char *optionValue = defGetString(option); char *optionValue = defGetString(option);
if (strcmp(option->defname,"template") == 0 && strcmp(optionValue, "template1") != 0) if (strcmp(option->defname, "template") == 0 && strcmp(optionValue, "template1") != 0)
{ {
ereport(ERROR, errmsg(
ereport(ERROR,errmsg("Only template1 is supported as template parameter for CREATE DATABASE")); "Only template1 is supported as template parameter for CREATE DATABASE"));
} }
} }

View File

@ -196,8 +196,6 @@ extern void SendInterTableRelationshipCommands(MetadataSyncContext *context);
"SELECT pg_catalog.worker_drop_sequence_dependency(%s);" "SELECT pg_catalog.worker_drop_sequence_dependency(%s);"
#define DISABLE_DDL_PROPAGATION "SET citus.enable_ddl_propagation TO 'off'" #define DISABLE_DDL_PROPAGATION "SET citus.enable_ddl_propagation TO 'off'"
#define BEGIN_TRANSACTION "BEGIN"
#define COMMIT_TRANSACTION "COMMIT"
#define ENABLE_DDL_PROPAGATION "SET citus.enable_ddl_propagation TO 'on'" #define ENABLE_DDL_PROPAGATION "SET citus.enable_ddl_propagation TO 'on'"
#define DISABLE_METADATA_SYNC "SET citus.enable_metadata_sync TO 'off'" #define DISABLE_METADATA_SYNC "SET citus.enable_metadata_sync TO 'off'"
#define ENABLE_METADATA_SYNC "SET citus.enable_metadata_sync TO 'on'" #define ENABLE_METADATA_SYNC "SET citus.enable_metadata_sync TO 'on'"