mirror of https://github.com/citusdata/citus.git
Moves validation to preprocess for createdb
parent
712fd8ebf3
commit
a9977e8840
|
@ -21,6 +21,7 @@
|
||||||
#include "catalog/pg_database_d.h"
|
#include "catalog/pg_database_d.h"
|
||||||
#include "catalog/pg_tablespace.h"
|
#include "catalog/pg_tablespace.h"
|
||||||
#include "commands/dbcommands.h"
|
#include "commands/dbcommands.h"
|
||||||
|
#include "commands/defrem.h"
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
|
@ -270,6 +271,55 @@ PreprocessAlterDatabaseSetStmt(Node *node, const char *queryString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function validates the options provided for the CREATE DATABASE command.
|
||||||
|
* It iterates over each option in the stmt->options list and checks if it's supported.
|
||||||
|
* If an unsupported option is found, or if a supported option has an invalid value,
|
||||||
|
* it raises an error.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* stmt: A CreatedbStmt struct representing a CREATE DATABASE command.
|
||||||
|
* The options field is a list of DefElem structs, each representing an option.
|
||||||
|
*
|
||||||
|
* Currently, this function checks for the following:
|
||||||
|
* - The "oid" option is not supported.
|
||||||
|
* - The "template" option is only supported with the value "template1".
|
||||||
|
* - The "strategy" option is only supported with the value "wal_log".
|
||||||
|
*
|
||||||
|
* If any of these checks fail, the function calls ereport to raise an error.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt)
|
||||||
|
{
|
||||||
|
DefElem *option = NULL;
|
||||||
|
foreach_ptr(option, stmt->options)
|
||||||
|
{
|
||||||
|
if (strcmp(option->defname, "oid") == 0)
|
||||||
|
{
|
||||||
|
ereport(ERROR,
|
||||||
|
errmsg("CREATE DATABASE option \"%s\" is not supported",
|
||||||
|
option->defname));
|
||||||
|
}
|
||||||
|
|
||||||
|
char *optionValue = defGetString(option);
|
||||||
|
|
||||||
|
if (strcmp(option->defname, "template") == 0 && strcmp(optionValue,
|
||||||
|
"template1") != 0)
|
||||||
|
{
|
||||||
|
ereport(ERROR, errmsg("Only template1 is supported as template "
|
||||||
|
"parameter for CREATE DATABASE"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(option->defname, "strategy") == 0 && strcmp(optionValue, "wal_log") !=
|
||||||
|
0)
|
||||||
|
{
|
||||||
|
ereport(ERROR, errmsg("Only wal_log is supported as strategy "
|
||||||
|
"parameter for CREATE DATABASE"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PostprocessAlterDatabaseStmt is executed before the statement is applied to the local
|
* PostprocessAlterDatabaseStmt is executed before the statement is applied to the local
|
||||||
* postgres instance.
|
* postgres instance.
|
||||||
|
@ -288,8 +338,9 @@ PreprocessCreateDatabaseStmt(Node *node, const char *queryString,
|
||||||
|
|
||||||
EnsureCoordinator();
|
EnsureCoordinator();
|
||||||
|
|
||||||
/*Validate the statement */
|
/*validate the statement*/
|
||||||
DeparseTreeNode(node);
|
CreatedbStmt *stmt = castNode(CreatedbStmt, node);
|
||||||
|
EnsureSupportedCreateDatabaseCommand(stmt);
|
||||||
|
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,37 +251,6 @@ DeparseAlterDatabaseSetStmt(Node *node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Validates for if option is template, lc_type, locale or lc_collate, propagation will
|
|
||||||
* not be supported since template and strategy options are not stored in the catalog
|
|
||||||
* and lc_type, locale and lc_collate options depends on template parameter.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
ValidateCreateDatabaseOptions(DefElem *option)
|
|
||||||
{
|
|
||||||
if (strcmp(option->defname, "oid") == 0)
|
|
||||||
{
|
|
||||||
ereport(ERROR,
|
|
||||||
errmsg("CREATE DATABASE option \"%s\" is not supported",
|
|
||||||
option->defname));
|
|
||||||
}
|
|
||||||
|
|
||||||
char *optionValue = defGetString(option);
|
|
||||||
|
|
||||||
if (strcmp(option->defname, "template") == 0 && strcmp(optionValue, "template1") != 0)
|
|
||||||
{
|
|
||||||
ereport(ERROR, errmsg("Only template1 is supported as template "
|
|
||||||
"parameter for CREATE DATABASE"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(option->defname, "strategy") == 0 && strcmp(optionValue, "wal_log") != 0)
|
|
||||||
{
|
|
||||||
ereport(ERROR, errmsg("Only wal_log is supported as strategy "
|
|
||||||
"parameter for CREATE DATABASE"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt)
|
AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt)
|
||||||
{
|
{
|
||||||
|
@ -293,7 +262,7 @@ AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt)
|
||||||
|
|
||||||
foreach_ptr(option, stmt->options)
|
foreach_ptr(option, stmt->options)
|
||||||
{
|
{
|
||||||
ValidateCreateDatabaseOptions(option);
|
/*ValidateCreateDatabaseOptions(option); */
|
||||||
|
|
||||||
DefElemOptionToStatement(buf, option, create_database_option_formats,
|
DefElemOptionToStatement(buf, option, create_database_option_formats,
|
||||||
lengthof(create_database_option_formats));
|
lengthof(create_database_option_formats));
|
||||||
|
|
Loading…
Reference in New Issue