@function alterTable

alter an existing table

@param {object} args

@returns {Promise}

@throws {Error}
507796
async function alterTable (args) {
    // get args object
    args = requireValidOptionalObject(args)
    // get existing schema
    var schema = requireValidSchema(args.schema)
    // modify existing columns
    await Promise.each(this.columnNames, async name => {
        // skip unless column exists
        if (!schema.columns[name]) {
            return
        }
        // attempt to alter existing column if model does not match schema
        await this.alterColumn({
            column: name,
            schema: schema,
            session: args.session,
        })
    })
    // create new columns
    await Promise.each(this.columnNames, async name => {
        // skip if column exists
        if (schema.columns[name]) {
            return
        }
        // get spec
        var spec = this.columns[name]
        // attempt to add column to table
        await this.createColumn({
            column: {
                name: name,
                spec: spec,
            },
            session: args.session,
        })
    })
}
228174
public function modifyTable()
    {
        $table = $this->getTable();

        if (!$table->hasColumn($this->getParameter('rank_column'))) {
            $table->addColumn([
                'name' => $this->getParameter('rank_column'),
                'type' => 'INTEGER'
            ]);
        }

        if ($this->useScope()) {
            if (!$this->hasMultipleScopes() && !$table->hasColumn($this->getParameter('scope_column'))) {
                $table->addColumn([
                    'name' => $this->getParameter('scope_column'),
                    'type' => 'INTEGER'
                ]);
            }

            $scopes = $this->getScopes();
            if (0 === count($scopes)) {
                throw new \InvalidArgumentException(sprintf(
                    'The sortable behavior in `%s` needs a `scope_column` parameter.',
                    $this->getTable()->getName()
                ));
            }
        }
    }
687457
function (values) {
            var ds = this.mergeOptions({replace: true});
            return ds.insertSql.apply(ds, argsToArray(arguments));
        }
598424
function (arg) {
						if ( ! arg.allow ){
							return;
						}

						var exist = false;
						for (var i in data.allow) {
							if (data.allow[i] === arg.allow) {
								exist = true;
							}
						}
						if ( exist === false ) {
							data.allow[data.allow.length] = arg.allow;
						}
					}
203755
function (table, key, obj, clientIdentity) {
            // Create table if it doesnt exist:
            db.tables[table] = db.tables[table] || {};
            // Put the obj into to table
            db.tables[table][key] = obj;
            // Register the change:
            db.changes.push({
                rev: ++db.revision,
                source: clientIdentity,
                type: CREATE,
                table: table,
                key: key,
                obj: obj
            });
            db.trigger();
        }
140280
@NonNull
  public static AlterTableStart alterTable(@NonNull String tableName) {
    return alterTable(CqlIdentifier.fromCql(tableName));
  }
485156
private function alterTableMigrate(array $alterDef, array $options = []) {
        $table = $alterDef['name'];
        $currentDef = $this->fetchTableDef($table);

        // Merge the table definitions if we aren't dropping stuff.
        if (!self::val(Db::OPTION_DROP, $options)) {
            $tableDef = $this->mergeTableDefs($currentDef, $alterDef);
        } else {
            $tableDef = $alterDef['def'];
        }

        // Drop all of the indexes on the current table.
        foreach (self::val('indexes', $currentDef, []) as $indexDef) {
            if (self::val('type', $indexDef, Db::INDEX_IX) === Db::INDEX_IX) {
                $this->dropIndex($indexDef['name']);
            }
        }

        $tmpTable = $table.'_'.time();

        // Rename the current table.
        $this->renameTable($table, $tmpTable);

        // Create the new table.
        $this->createTableDb($tableDef, $options);

        // Figure out the columns that we can insert.
        $columns = array_keys(array_intersect_key($tableDef['columns'], $currentDef['columns']));

        // Build the insert/select statement.
        $sql = 'insert into '.$this->prefixTable($table)."\n".
            $this->bracketList($columns, '`')."\n".
            $this->buildSelect($tmpTable, [], ['columns' => $columns]);

        $this->queryDefine($sql);

        // Drop the temp table.
        $this->dropTable($tmpTable);
    }
126860
function initNew (args) {
    // get module
    var module = this.component.module
    // if module has new method run it
    if (module.new) {
        // call new method with original new args
        this.promise = module.new(args.args).then(res => {
            // if new returns undefined do not set
            if (!defined(res)) {
                return
            }
            // require data to be object
            this.assert(typeof res === 'object' && res, 110)
            // if data is set then use it
            if (defined(res.data)) {
                // require data to be object
                this.assert(typeof res.data === 'object' && res.data, 110)
                // set component data to data returned by new method
                this.data = res.data
            }
            // if id set set it data use it
            if (defined(res.id)) {
                this.id = res.id
            }
        })
    }
    // otherwise set resolved promise
    else {
        // use any args for data
        _.merge(this.data, args.args)
        // set init promise as resolved
        this.promise = Promise.resolve()
    }
}
138660
public static function table_alter( $table, $changes ) {

		/**
		 * @var $wpdb wpdb
		 */
		global $wpdb;

		$sql = "ALTER TABLE `{$wpdb->prefix}" . self::$prefix . "{$table}` {$changes}";

		return self::query( $sql );
	}
485522
function pgsqlBulkUpsert(model, data) {
  var queries = [];

  // Transform data
  _.each(data, function(d) {
    // TODO: Postgres does not have easy UPSERT syntax, the ON CONFLICT UPDATE requires specific columns
    var query = "INSERT INTO " + model.tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])";
    query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));
    query = query.replace("[[VALUES]]", _.map(d, function(v) {
      return sequelizeSS.escape(v, undefined, "postgres");
    }).join(", "));
    queries.push(query);
  });

  // Create final output and format
  return queries.join("; ");
}
769356
function() {
	var me = {};
	var db = common.config.database;

	me.act = new NobleMachine();

	return _.extend(me, {
		create_table: function(name, definer) {
			var t = new TableDefinition(name, 'create', definer);
			me.act.next(t.act);
		},

		change_table: function(name, definer) {
			var t = new TableDefinition(name, 'alter', definer);
			me.act.next(t.act);
		},

		drop_table: function(name) {
			me.act.next(db.query(" DROP TABLE `" + name + "`;"));
		},

		rename_table: function(name, newname) {
			me.act.next(db.query(" ALTER TABLE `" + name + "` RENAME `" + newname + "`"));
		},
	});
}
371707
def change_column_if_table_exists(self,
                                      tablename: str,
                                      oldfieldname: str,
                                      newfieldname: str,
                                      newdef: str) -> Optional[int]:
        """"""
        if not self.table_exists(tablename):
            return None
        if not self.column_exists(tablename, oldfieldname):
            return None
        sql = "ALTER TABLE {t} CHANGE COLUMN {old} {new} {newdef}".format(
            t=tablename,
            old=oldfieldname,
            new=newfieldname,
            newdef=newdef,
        )
        log.info(sql)
        return self.db_exec_literal(sql)
377232
def db_alter(name, user=None, host=None, port=None, maintenance_db=None,
             password=None, tablespace=None, owner=None, owner_recurse=False,
             runas=None):
    '''
    
    '''
    if not any((tablespace, owner)):
        return True  # Nothing todo?

    if owner and owner_recurse:
        ret = owner_to(name, owner,
                       user=user,
                       host=host,
                       port=port,
                       password=password,
                       runas=runas)
    else:
        queries = []
        if owner:
            queries.append('ALTER DATABASE "{0}" OWNER TO "{1}"'.format(
                name, owner
            ))
        if tablespace:
            queries.append('ALTER DATABASE "{0}" SET TABLESPACE "{1}"'.format(
                name, tablespace
            ))
        for query in queries:
            ret = _psql_prepare_and_run(['-c', query],
                                        user=user, host=host, port=port,
                                        maintenance_db=maintenance_db,
                                        password=password, runas=runas)

    if ret['retcode'] != 0:
        return False

    return True
321157
function(tableName, columnName, callback) {
    var cqlString = util.format('ALTER TABLE %s DROP %s', tableName, columnName);
    return this.runSql(cqlString, callback).nodeify(callback);
  }
280822
function handleArguments(args) {
  return new Promise(function(resolve, reject) {
    var requires = [];
    var promises = [];

    // check for Promises in args
    if (args && args instanceof Array) {
      args.some(function (arg, i) {
        if ((arg.value === null || typeof(arg.value) == 'undefined') && arg.optional) {
          return true;
        }

        if (arg.value && Array.isArray(arg.value) && arg.optional && arg.value.length == 0) {
          return true;
        }

        if (arg.type == 'string') {
          var s = '"' + arg.value.replace(/"/g, '\\\"') + '"';
          promises.push(Promise.resolve(s));
        } else if (arg.type == 'lambda') {
          promises.push(serializeLambda(arg.value));
        } else if (arg.type == 'lambdaArgs') {
          promises.push(new Promise(function(resolve, reject) {
            handleArrayArgument(arg.value).then(function (result) {
              resolve(result);
            }).catch(reject);
          }));
        } else if (arg.type == 'map') {
          promises.push(Promise.resolve(JSON.stringify(arg.value)));
        } else if (arg.type == 'promise') {
          promises.push(new Promise(function(resolve, reject) {
            arg.value.then(function(val) {
              if (typeof(val) == 'string') {
                if (isNaN(val)) {
                  // a string
                  var s = '"' + val.replace(/"/g, '\\\"') + '"';
                  resolve(s);
                } else {
                  resolve(parseFloat(val));
                }
              } else {
                resolve(val);
              }
            });
          }));
        } else if (arg.value.refIdP) {
          promises.push(arg.value.refIdP);
        } else if (arg.type == 'List') {
          promises.push(Promise.resolve(arg.value.toString()));
        } else if (arg.type == 'array') {
          // simple array argument
          promises.push(handleArrayArgument(arg.value));
        } else if (arg.type == '_eclairSerialize') {
          if (arg.value._eclairSerialize == 'staticProperty') {
            var val = arg.value.ref.name + '.' + arg.value.value;
            promises.push(Promise.resolve(val));
            requires.push({name: arg.value.ref.name, moduleLocation: arg.value.ref.moduleLocation});
          }
        } else if (Array.isArray(arg.value)) {
          // TODO: should we try to wrap the array if it isn't?
          promises.push(new Promise(function (resolve, reject) {
            handleArguments(arg.value).then(function (result) {
              if (result.requires.length > 0) {
                result.requires.forEach(function (r) {
                  requires.push(r)
                });
              }

              resolve('[' + result.args + ']');
            }).catch(reject);
          }));
        } else if (arg.type == '_eclairForceFloat') {
          var val = arg.value.value;
          if (val.toString().indexOf('.') === -1) {
            val = val.toFixed(1);
          }
          promises.push(Promise.resolve(val));
        } else if (arg.type == '_eclairLocal') {
          promises.push(Promise.resolve(arg.value._generateRemote().refIdP));
        } else if (arg.type == 'sparkclassref') {
          // we have a spark class reference, so return its name
          promises.push(Promise.resolve(arg.value.name));
          // add the class to the requires list
          requires.push({name: arg.value.name, moduleLocation: arg.value.moduleLocation});
        } else {
          promises.push(Promise.resolve(arg.value));
        }

        return false;
      });
    }

    Promise.all(promises).then(function(finalArgs) {
      resolve({args: finalArgs, requires: requires});
      //resolve(finalArgs);
    }).catch(function(e) {
      console.log(e);
      reject(e)
    });
  });
}
1169929
function applyNew(args) {
        // create an object with ctor's prototype but without
        // calling ctor on it.
        var ctor = args.callee, t = forceNew(ctor);
        // execute the real constructor on the new object
        ctor.apply(t, args);
        return t;
    }
1050333
function createTable (db, name) {
  return r.db(db).tableCreate(name).run().then(function () {
    console.log('RETHINKDB: Created Table', name, 'on', db)
  }).catch(function (err) {
    console.log('RETHINKDB: Table', name, 'on', db, 'exists')
  })
}