This is only used for upgrading from pre sqlg_schema sqlg to a sqlg_schema
198770
@Override
    public PropertyType sqlTypeToPropertyType(SqlgGraph sqlgGraph, String schema, String table, String column, int sqlType, String typeName, ListIterator<Triple<String, Integer, String>> metaDataIter) {
        switch (sqlType) {
            case Types.BIT:
                return PropertyType.BOOLEAN;
            case Types.SMALLINT:
                return PropertyType.SHORT;
            case Types.INTEGER:
                return PropertyType.INTEGER;
            case Types.BIGINT:
                return PropertyType.LONG;
            case Types.REAL:
                return PropertyType.FLOAT;
            case Types.DOUBLE:
                return PropertyType.DOUBLE;
            case Types.VARCHAR:
                return PropertyType.STRING;
            case Types.TIMESTAMP:
                return PropertyType.LOCALDATETIME;
            case Types.DATE:
                return PropertyType.LOCALDATE;
            case Types.TIME:
                return PropertyType.LOCALTIME;
            case Types.OTHER:
                //this is a f up as only JSON can be used for other.
                //means all the gis data types which are also OTHER are not supported
                switch (typeName) {
                    case "jsonb":
                        return PropertyType.JSON;
                    case "geometry":
                        return getPostGisGeometryType(sqlgGraph, schema, table, column);
                    case "geography":
                        return getPostGisGeographyType(sqlgGraph, schema, table, column);
                    default:
                        throw new RuntimeException("Other type not supported " + typeName);

                }
            case Types.BINARY:
                return BYTE_ARRAY;
            case Types.ARRAY:
                return sqlArrayTypeNameToPropertyType(typeName, sqlgGraph, schema, table, column, metaDataIter);
            default:
                throw new IllegalStateException("Unknown sqlType " + sqlType);
        }
    }
236671
def upgrade():
    """"""
    if op._proxy.migration_context.dialect.name == 'postgresql':
        op.alter_column(
            'records_metadata',
            'json',
            type_=sa.dialects.postgresql.JSONB,
            postgresql_using='json::text::jsonb'
        )
148794
def get_upsert_sql(
        self,
        rows,
        unique_fields,
        update_fields,
        auto_field_name=None,
        only_insert=False,
        return_rows=True
    ):
        
        ModelClass = self.tables[0].model

        # Use all fields except pk unless the uniqueness constraint is the pk field. Null pk field rows will be
        # excluded in the upsert method before calling this method
        all_fields = [field for field in ModelClass._meta.fields if field.column != auto_field_name]
        if auto_field_name in unique_fields and not only_insert:
            all_fields = [field for field in ModelClass._meta.fields]

        all_field_names = [field.column for field in all_fields]
        all_field_names_sql = ', '.join(all_field_names)

        # Convert field names to db column names
        unique_fields = [
            ModelClass._meta.get_field(unique_field)
            for unique_field in unique_fields
        ]
        update_fields = [
            ModelClass._meta.get_field(update_field)
            for update_field in update_fields
        ]

        unique_field_names_sql = ', '.join([
            field.column for field in unique_fields
        ])
        update_fields_sql = ', '.join([
            '{0} = EXCLUDED.{0}'.format(field.column)
            for field in update_fields
        ])

        row_values = []
        sql_args = []

        for row in rows:
            placeholders = []
            for field in all_fields:
                # Convert field value to db value
                # Use attname here to support fields with custom db_column names
                sql_args.append(field.get_db_prep_save(getattr(row, field.attname), self.connection))
                placeholders.append('%s')
            row_values.append('({0})'.format(', '.join(placeholders)))
        row_values_sql = ', '.join(row_values)

        if update_fields:
            self.sql = 'INSERT INTO {0} ({1}) VALUES {2} ON CONFLICT ({3}) DO UPDATE SET {4} {5}'.format(
                self.tables[0].get_identifier(),
                all_field_names_sql,
                row_values_sql,
                unique_field_names_sql,
                update_fields_sql,
                'RETURNING *' if return_rows else ''
            )
        else:
            self.sql = 'INSERT INTO {0} ({1}) VALUES {2} ON CONFLICT ({3}) {4} {5}'.format(
                self.tables[0].get_identifier(),
                all_field_names_sql,
                row_values_sql,
                unique_field_names_sql,
                'DO UPDATE SET {0}=EXCLUDED.{0}'.format(unique_fields[0].column),
                'RETURNING *' if return_rows else ''
            )

        return self.sql, sql_args
1372715
def ibis_schema_apply_to(schema, df):
    

    for column, dtype in schema.items():
        pandas_dtype = dtype.to_pandas()
        col = df[column]
        col_dtype = col.dtype

        try:
            not_equal = pandas_dtype != col_dtype
        except TypeError:
            # ugh, we can't compare dtypes coming from pandas, assume not equal
            not_equal = True

        if not_equal or dtype == dt.string:
            df[column] = convert(col_dtype, dtype, col)

    return df
535033
public function upgradeSchema(Schema $schema)
    {
        try {
            $table = $schema->getTable('SystemDatabaseQueryLog');
            $table->addColumn('ID', 'integer', ['unsigned' => true, 'autoincrement' => true]);
            $table->setPrimaryKey(['ID']);
        } catch (\Exception $e) {
        }
    }
1059567
public void updateSchemaVersion(VersionComparator version) throws SQLException {
        PreparedStatement statement = null;
        PreparedStatement updateStatement = null;
        ResultSet results = null;
        try {
            statement = connection.prepareStatement("SELECT \"VERSION\" FROM \"SCHEMAVERSION\"");
            results = statement.executeQuery();

            if (results.next()) {
                final VersionComparator currentVersion = new VersionComparator(results.getString(1));
                if (version == null || currentVersion.isNewerThan(version)) {
                    return;
                }
                updateStatement = connection.prepareStatement("UPDATE \"SCHEMAVERSION\" SET \"VERSION\" = ?");
            } else {
                // Does not exist. Populate schema table with current running version
                version = new VersionComparator(Config.getInstance().getApplicationVersion());
                updateStatement = connection.prepareStatement("INSERT INTO \"SCHEMAVERSION\" (\"VERSION\") VALUES (?)");
            }

            LOGGER.debug("Updating database schema to: " + version.toString());

            updateStatement.setString(1, version.toString());
            updateStatement.executeUpdate();
            connection.commit();
        } finally {
            DbUtil.close(results);
            DbUtil.close(updateStatement);
            DbUtil.close(statement);
            //DbUtil.close(connection); // do not close connection
        }
    }
211611
def refresh_schema(self, exclude_system_tables=True, use_cache=False):
        

        col_meta, table_meta = self._get_db_metadata(exclude_system_tables, use_cache)
        tables = self._gen_tables_from_col_tuples(col_meta)

        # Three modes for refreshing schema
        # 1. load directly from cache
        # 2. use a single query for getting all key relationships
        # 3. use the naive approach
        if use_cache:
            # generate our Tables, and load them into a TableSet
            self._tables = TableSet([Table(self.con, self._query_templates, table_meta[t]['schema'], t, tables[t],
                                           keys_per_column=self.keys_per_column,
                                           foreign_keys=table_meta[t]['foreign_keys']['columns'],
                                           ref_keys=table_meta[t]['ref_keys']['columns'])
                                     for t in sorted(tables.keys())])

        # optimize the foreign/ref key query by doing it one time, database-wide, if query is available
        elif not use_cache and isinstance(self._query_templates.get('system', {}).get('foreign_keys_for_db', None), str):

            self.cur.execute(self._query_templates['system']['foreign_keys_for_db'])
            table_db_foreign_keys = defaultdict(list)
            for rel in self.cur:
                # second value in relationship tuple is the table name
                table_db_foreign_keys[rel[1]].append(rel)

            self.cur.execute(self._query_templates['system']['ref_keys_for_db'])
            table_db_ref_keys = defaultdict(list)
            for rel in self.cur:
                # second value in relationship tuple is the table name
                table_db_ref_keys[rel[1]].append(rel)

            # generate our Tables, and load them into a TableSet
            self._tables = TableSet([Table(self.con, self._query_templates, tables[t][0].schema, t, tables[t],
                                           keys_per_column=self.keys_per_column,
                                           foreign_keys=table_db_foreign_keys[t], ref_keys=table_db_ref_keys[t])
                                     for t in sorted(tables.keys())])
        elif not use_cache:
            self._tables = TableSet([Table(self.con, self._query_templates, tables[t][0].schema, t, tables[t],
                                           keys_per_column=self.keys_per_column) for t in sorted(tables.keys())])

        sys.stderr.write("done!\n")
1184415
def to_sql
      @to_sql ||= begin
        if eager_loading?
          apply_join_dependency do |relation, join_dependency|
            relation = join_dependency.apply_column_aliases(relation)
            relation.to_sql
          end
        else
          conn = klass.connection
          conn.unprepared_statement { conn.to_sql(arel) }
        end
      end
    end
1366222
def upgrade():
    """"""
    op.create_table(
        'pidstore_pid',
        sa.Column('created', sa.DateTime(), nullable=False),
        sa.Column('updated', sa.DateTime(), nullable=False),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('pid_type', sa.String(length=6), nullable=False),
        sa.Column('pid_value', sa.String(length=255), nullable=False),
        sa.Column('pid_provider', sa.String(length=8), nullable=True),
        sa.Column('status', sa.CHAR(1), nullable=False),
        sa.Column('object_type', sa.String(length=3), nullable=True),
        sa.Column(
            'object_uuid',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=True
        ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(
        'idx_object', 'pidstore_pid', ['object_type', 'object_uuid'],
        unique=False
    )
    op.create_index('idx_status', 'pidstore_pid', ['status'], unique=False)
    op.create_index(
        'uidx_type_pid', 'pidstore_pid', ['pid_type', 'pid_value'],
        unique=True
    )
    op.create_table(
        'pidstore_recid',
        sa.Column('recid', sa.BigInteger(), nullable=False),
        sa.PrimaryKeyConstraint('recid')
    )
    op.create_table(
        'pidstore_redirect',
        sa.Column('created', sa.DateTime(), nullable=False),
        sa.Column('updated', sa.DateTime(), nullable=False),
        sa.Column(
            'id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False
        ),
        sa.Column('pid_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['pid_id'],
            [u'pidstore_pid.id'],
            onupdate='CASCADE',
            ondelete='RESTRICT'
        ),
        sa.PrimaryKeyConstraint('id')
    )
173671
function(db_schema) {

        // add existing object store
        if (schema instanceof ydn.db.schema.EditableDatabase) {
          var editable = /** @type {ydn.db.schema.EditableDatabase} */ (schema);
          for (var i = 0; i < db_schema.stores.length; i++) {
            if (!editable.hasStore(db_schema.stores[i].getName())) {
              editable.addStore(db_schema.stores[i].clone());
            }
          }
        }

        var diff_msg = schema.difference(db_schema, false, true);
        if (diff_msg.length > 0) {
          goog.log.log(me.logger, goog.log.Level.FINER, 'Schema change require for difference in ' +
              diff_msg);

          var on_completed = function(t, e) {
            if (t == ydn.db.base.TxEventTypes.COMPLETE) {
              setDb(db);
            } else {
              goog.log.error(me.logger, 'Fail to update version on ' + db.name + ':' +
                  db.version);
              setDb(null, e);
            }
          };

          var next_version = goog.isNumber(db.version) ? db.version + 1 : 1;

          if (!ydn.db.base.OLD_INDEXEDDB_SUPPORT || 'IDBOpenDBRequest' in goog.global) {
            db.close();
            var req = ydn.db.base.indexedDb.open(
                dbname, /** @type {number} */ (next_version));
            req.onupgradeneeded = function(ev) {
              var db = ev.target.result;
              goog.log.log(me.logger, goog.log.Level.FINER, 're-open for version ' + db.version);
              updateSchema(db, req['transaction'], false);

            };
            req.onsuccess = function(ev) {
              setDb(ev.target.result);
            };
            req.onerror = function(e) {
              goog.log.log(me.logger, goog.log.Level.FINER, me + ': fail.');
              setDb(null);
            };
          } else if (ydn.db.base.OLD_INDEXEDDB_SUPPORT) {
            var ver_request = db.setVersion(next_version + '');

            ver_request.onfailure = function(e) {
              goog.log.warning(me.logger, 'migrating from ' + db.version + ' to ' +
                  next_version + ' failed.');
              setDb(null, e);
            };


            var trans = ver_request['transaction'];
            ver_request.onsuccess = function(e) {

              ver_request['transaction'].oncomplete = tr_on_complete;

              updateSchema(db, ver_request['transaction'], true);
            };

            var tr_on_complete = function(e) {

              // for old format.
              // by reopening the database, we make sure that we are not in
              // version change state since transaction cannot open during
              // version change state.
              // db.close(); // necessary - cause error ?
              var reOpenRequest = ydn.db.base.indexedDb.open(dbname);
              reOpenRequest.onsuccess = function(rev) {
                var db = rev.target.result;
                goog.log.log(me.logger, goog.log.Level.FINER, me + ': OK.');
                setDb(db);
              };

              reOpenRequest.onerror = function(e) {
                goog.log.log(me.logger, goog.log.Level.FINER, me + ': fail.');
                setDb(null);
              };
            };

            if (goog.isDefAndNotNull(ver_request['transaction'])) {
              ver_request['transaction'].oncomplete = tr_on_complete;
            }

          }

        } else {
          setDb(db);
        }
      }
714386
def upgrade(cfg):
    """"""
    db_node = cfg["db"]
    old_db_elems = ["host", "name", "port", "pass", "user", "dialect"]
    has_old_db_elems = [x in db_node for x in old_db_elems]

    if any(has_old_db_elems):
        print("Old database configuration found. "
              "Converting to new connect_string. "
              "This will *not* be stored in the configuration automatically.")
        cfg["db"]["connect_string"] = \
            "{dialect}://{user}:{password}@{host}:{port}/{name}".format(
                dialect=cfg["db"]["dialect"]["value"],
                user=cfg["db"]["user"]["value"],
                password=cfg["db"]["pass"]["value"],
                host=cfg["db"]["host"]["value"],
                port=cfg["db"]["port"]["value"],
                name=cfg["db"]["name"]["value"])
1147007
def ogr2pg(
        self,
        in_file,
        in_layer=None,
        out_layer=None,
        schema="public",
        s_srs=None,
        t_srs="EPSG:3005",
        sql=None,
        dim=2,
        cmd_only=False,
        index=True
    ):
        
        # if not provided a layer name, use the name of the input file
        if not in_layer:
            in_layer = os.path.splitext(os.path.basename(in_file))[0]
        if not out_layer:
            out_layer = in_layer.lower()
        command = [
            "ogr2ogr",
            "-t_srs",
            t_srs,
            "-f",
            "PostgreSQL",
            "PG:host={h} user={u} dbname={db} password={pwd}".format(
                h=self.host, u=self.user, db=self.database, pwd=self.password
            ),
            "-lco",
            "OVERWRITE=YES",
            "-overwrite",
            "-lco",
            "SCHEMA={schema}".format(schema=schema),
            "-lco",
            "GEOMETRY_NAME=geom",
            "-dim",
            "{d}".format(d=dim),
            "-nlt",
            "PROMOTE_TO_MULTI",
            "-nln",
            out_layer,
            in_file
        ]
        if sql:
            command.insert(
                len(command),
                "-sql"
            )
            command.insert(
                len(command),
                "SELECT * FROM {} WHERE {}".format(in_layer, sql)
            )
            command.insert(len(command), "-dialect")
            command.insert(len(command), "SQLITE")
        # only add output layer name if sql not included (it gets ignored)
        if not sql:
            command.insert(
                len(command),
                in_layer
            )
        if s_srs:
            command.insert(len(command), "-s_srs")
            command.insert(len(command), s_srs)
        if not index:
            command.insert(len(command), "-lco")
            command.insert(len(command), "SPATIAL_INDEX=NO")
        if cmd_only:
            return " ".join(command)
        else:
            subprocess.run(command)
776364
def _db_upgrade(self, db_name):
        
        current_db_version = self._get_db_version()
        self._execute(db_schema.functions)
        for i in range(current_db_version, nipap.__db_version__):
            self._logger.info("Upgrading DB schema:", i, "to", i+1)
            upgrade_sql = db_schema.upgrade[i-1] # 0 count on array
            self._execute(upgrade_sql % (db_name))
        self._execute(db_schema.triggers)
1365918
private void migrateTable(TablePkFkVO table) throws SQLException {
		logger.info("Migrating Table: {}", table.getName());

		helper.executeDDL("renameColumn",
			ObjectBuilder.<String, Object>map()
				.put("table", table.getName())
				.put("col_cur_name", table.getPkColumn())
				.put("col_new_name", "old_" + table.getPkColumn())
				.get()
		);
		logger.info("\tRename PK column: {}", table.getPkColumn());

		helper.executeDDL("addColumn",
			ObjectBuilder.<String, Object>map()
				.put("table", table.getName())
				.put("col_name", table.getPkColumn())
				.put("col_type", "varchar2(255 char)") //TODO
				.get()
		);
		logger.info("\tAdd new PK column: {}", table.getPkColumn());

		for (RefConsVO refConsVO : table.getReferencedBy()) {
			helper.executeDDL("renameColumn",
				ObjectBuilder.<String, Object>map()
					.put("table", refConsVO.getTableName())
					.put("col_cur_name", refConsVO.getColumnName())
					.put("col_new_name", "old_" + refConsVO.getColumnName())
					.get()
			);

			helper.executeDDL("addColumn",
				ObjectBuilder.<String, Object>map()
					.put("table", refConsVO.getTableName())
					.put("col_name", refConsVO.getColumnName())
					.put("col_type", "varchar2(255 char)") //TODO
					.get()
			);
		}
		logger.info("\tRename & Add FK columns");

		connection.setAutoCommit(false);

		try {
			String updateIdSql = String.format("update %1$s set %2$s = :new_id where old_%2$s = :cur_id",
				table.getName(), table.getPkColumn());
			NamedParameterStatement updateIdNps = helper.createNPS(XQuery.sql(updateIdSql));

			String selectIdsSql = String.format("select old_%s from %s", table.getPkColumn(), table.getName());
			List<Object> ids = helper.firstColAsList(XQuery.sql(selectIdsSql));
			for (Object id : ids) {
				Object newId = UUID.randomUUID().toString(); //TODO

				updateIdNps
					.setParameters(ObjectBuilder.<String, Object>map()
						.put("new_id", newId)
						.put("cur_id", id)
						.get())
					.executeUpdate();

				for (RefConsVO refConsVO : table.getReferencedBy()) {
					String updateFkSql = String.format("update %1$s set %2$s = :new_id where old_%2$s = :cur_id",
						refConsVO.getTableName(), refConsVO.getColumnName());
					NamedParameterStatement updateFkNps = helper.createNPS(XQuery.sql(updateFkSql));

					updateFkNps
						.setParameters(ObjectBuilder.<String, Object>map()
							.put("new_id", newId)
							.put("cur_id", id)
							.get())
						.executeUpdate();
				}
			}

			connection.commit();
		} catch (SQLException e) {
			logger.error("Data Insert", e);
			connection.rollback();
			throw e;
		}

		for (RefConsVO refConsVO : table.getReferencedBy()) {
			helper.executeDDL("dropCons", ObjectBuilder.<String, Object>map()
				.put("table", refConsVO.getTableName())
				.put("cons", refConsVO.getConsName())
				.get());

			dropOtherCons(refConsVO.getTableName(), "OLD_" + refConsVO.getColumnName());
		}

		helper.executeDDL("dropCons", ObjectBuilder.<String, Object>map()
			.put("table", table.getName())
			.put("cons", table.getPkConstraint())
			.get());

		dropOtherCons(table.getName(), "OLD_" + table.getPkColumn());


		helper.executeDDL("addPkCons", ObjectBuilder.<String, Object>map()
			.put("table", table.getName())
			.put("cons", table.getPkConstraint())
			.put("col", table.getPkColumn())
			.get());

		for (RefConsVO refConsVO : table.getReferencedBy()) {
			helper.executeDDL("addFkCons", ObjectBuilder.<String, Object>map()
				.put("table", refConsVO.getTableName())
				.put("cons", refConsVO.getConsName())
				.put("col", refConsVO.getColumnName())
				.put("dest_table", table.getName())
				.get());
		}
	}
472793
def scripts_previously_run(scripts)
      if scripts.empty? || !@db.schema_schema_evolution_manager_exists?
        []
      else
        sql = "select filename from %s.%s where filename in (%s)" % [Db.schema_name, @table_name, "'" + scripts.join("', '") + "'"]
        @db.psql_command(sql).strip.split
      end
    end
785854
@Override
  public boolean upgrade() {
    int schemaVersion = versionService.getSchemaVersion();
    if (schemaVersion < 31) {
      throw new UnsupportedOperationException(
          "Upgrading from schema version below 31 is not supported");
    }
    if (schemaVersion < versionService.getAppVersion()) {
      LOG.info(
          "Metadata version:{}, current version:{} upgrade needed",
          schemaVersion,
          versionService.getAppVersion());

      upgrades
          .stream()
          .filter(upgrade -> upgrade.getFromVersion() >= schemaVersion)
          .forEach(this::runUpgrade);

      versionService.setSchemaVersion(versionService.getAppVersion());

      LOG.info("Metadata upgrade done.");
      return true;
    } else {
      LOG.debug(
          "Metadata version:{}, current version:{} upgrade not needed",
          schemaVersion,
          versionService.getAppVersion());
      return false;
    }
  }
1042329
def copy(self, tx_ins=None, tx_outs=None, lock_time=None,
             expiry_height=None, tx_joinsplits=None, joinsplit_pubkey=None,
             joinsplit_sig=None):
        '''
        
        '''
        return OverwinterTx(
            tx_ins=tx_ins if tx_ins is not None else self.tx_ins,
            tx_outs=tx_outs if tx_outs is not None else self.tx_outs,
            lock_time=(lock_time if lock_time is not None
                       else self.lock_time),
            expiry_height=(expiry_height if expiry_height is not None
                           else self.expiry_height),
            tx_joinsplits=(tx_joinsplits if tx_joinsplits is not None
                           else self.tx_joinsplits),
            joinsplit_pubkey=(joinsplit_pubkey if joinsplit_pubkey is not None
                              else self.joinsplit_pubkey),
            joinsplit_sig=(joinsplit_sig if joinsplit_sig is not None
                           else self.joinsplit_sig))