[asterisk-commits] tilghman: branch tilghman/adaptive_realtime r116763 - in /team/tilghman/adapt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 15 20:42:03 CDT 2008
Author: tilghman
Date: Thu May 15 20:42:03 2008
New Revision: 116763
URL: http://svn.digium.com/view/asterisk?view=rev&rev=116763
Log:
Add table altering code; check updates for columns
Modified:
team/tilghman/adaptive_realtime/configs/res_pgsql.conf.sample
team/tilghman/adaptive_realtime/res/res_config_pgsql.c
Modified: team/tilghman/adaptive_realtime/configs/res_pgsql.conf.sample
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/configs/res_pgsql.conf.sample?view=diff&rev=116763&r1=116762&r2=116763
==============================================================================
--- team/tilghman/adaptive_realtime/configs/res_pgsql.conf.sample (original)
+++ team/tilghman/adaptive_realtime/configs/res_pgsql.conf.sample Thu May 15 20:42:03 2008
@@ -12,3 +12,11 @@
dbname=asterisk
dbuser=asterisk
dbpass=password
+;
+; requirements - At startup, each realtime family will make requirements
+; on the backend. There are several strategies for handling requirements:
+; warn - Warn if the required column does not exist.
+; createclose - Create columns as close to the requirements as possible.
+; createchar - Create char columns only
+;
+requirements=warn
Modified: team/tilghman/adaptive_realtime/res/res_config_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/res/res_config_pgsql.c?view=diff&rev=116763&r1=116762&r2=116763
==============================================================================
--- team/tilghman/adaptive_realtime/res/res_config_pgsql.c (original)
+++ team/tilghman/adaptive_realtime/res/res_config_pgsql.c Thu May 15 20:42:03 2008
@@ -78,6 +78,8 @@
static int parse_config(int reload);
static int pgsql_reconnect(const char *database);
static char *handle_cli_realtime_pgsql_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+
+enum { RQ_WARN, RQ_CREATECLOSE, RQ_CREATECHAR } requirements;
static struct ast_cli_entry cli_realtime[] = {
AST_CLI_DEFINE(handle_cli_realtime_pgsql_status, "Shows connection information for the PostgreSQL RealTime driver"),
@@ -948,6 +950,49 @@
break;
}
}
+
+ if (!column) {
+ if (requirements == RQ_WARN) {
+ ast_log(LOG_WARNING, "Table %s requires a column '%s' of size '%d', but no such column exists.\n", tablename, elm, size);
+ } else {
+ struct ast_str *sql = ast_str_create(100), *fieldtype = ast_str_create(16);
+ PGresult *res;
+
+ if (requirements == RQ_CREATECHAR || type == RQ_CHAR) {
+ ast_str_set(&fieldtype, 0, "CHAR(%d)", size);
+ } else if (type == RQ_INTEGER) {
+ ast_str_set(&fieldtype, 0, "INT%d", size < 5 ? 2 : (size < 11 ? 4 : 8));
+ } else if (type == RQ_FLOAT) {
+ ast_str_set(&fieldtype, 0, "FLOAT8");
+ } else if (type == RQ_DATE) {
+ ast_str_set(&fieldtype, 0, "DATE");
+ } else if (type == RQ_DATETIME) {
+ ast_str_set(&fieldtype, 0, "TIMESTAMP");
+ } else {
+ ast_free(sql);
+ ast_free(fieldtype);
+ continue;
+ }
+ ast_str_set(&sql, 0, "ALTER TABLE %s ADD COLUMN %s %s", tablename, elm, fieldtype->str);
+
+ ast_mutex_lock(&pgsql_lock);
+ if (!pgsql_reconnect(database)) {
+ ast_mutex_unlock(&pgsql_lock);
+ ast_log(LOG_ERROR, "Unable to add column: %s\n", sql->str);
+ ast_free(sql);
+ ast_free(fieldtype);
+ continue;
+ }
+
+ res = PQexec(pgsqlConn, sql->str);
+ if (PQresultStatus(res) != PGRES_COMMAND_OK) {
+ ast_log(LOG_ERROR, "Unable to add column: %s\n", sql->str);
+ }
+ PQclear(res);
+ ast_free(sql);
+ ast_free(fieldtype);
+ }
+ }
}
ast_mutex_unlock(&table->lock);
return res;
@@ -1080,6 +1125,17 @@
} else {
ast_copy_string(dbsock, s, sizeof(dbsock));
}
+
+ if (!(s = ast_variable_retrieve(config, "general", "requirements"))) {
+ ast_log(LOG_WARNING,
+ "PostgreSQL RealTime: no requirements setting found, using 'warn' as default.\n");
+ requirements = RQ_WARN;
+ } else if (!strcasecmp(s, "createclose")) {
+ requirements = RQ_CREATECLOSE;
+ } else if (!strcasecmp(s, "createchar")) {
+ requirements = RQ_CREATECHAR;
+ }
+
ast_config_destroy(config);
if (option_debug) {
More information about the asterisk-commits
mailing list