public void EnsureTable(NpgsqlConnection connection) { var tables = _npgHelper.GetTables(connection); if (tables.Contains(DbStr.Users)) { return; } var tb = new NpgTableInfoBuilder(DbStr.Users); tb.AddColumn(DbStr.Id, NpgDataType.Int8, true); tb.AddColumn(DbStr.Name, NpgDataType.Text, true); tb.AddColumn(DbStr.Description, NpgDataType.Text, true); tb.AddColumn(DbStr.Photo, NpgDataType.Bytea); tb.AddColumn(DbStr.Password, NpgDataType.Text); tb.AddColumn(DbStr.Enabled, NpgDataType.Bool, true); tb.AddColumn(DbStr.CanChange, NpgDataType.Bool, true); tb.AddColumn(DbStr.Privilege, NpgDataType.Int4); tb.AddPrimaryKey(DbStr.Id); NpgQuery createUsersTableQuery = _npgQueryHelper.CreateTable(tb.Build()); NpgQuery createNameIndexQuery = _npgQueryHelper.CreateIndex(DbStr.Users, unique: true, columns: DbStr.Name); _npgHelper.ExecuteScript(connection, new[] { createUsersTableQuery, createNameIndexQuery }); }
private void EnsureTable(int ordinal, IEnumerable <string> tables) { string tableName = GetTableName(ordinal); if (!tables.Contains(tableName)) { var tb = new NpgTableInfoBuilder(tableName); tb.AddColumn(DbStr.Time, NpgDataType.Int8, true); tb.AddPrimaryKey(DbStr.Time); NpgQuery createTableQuery = _npgQueryHelper.CreateTable(tb.Build()); _npgHelper.ExecuteScript(_connection, new[] { createTableQuery }); } var columns = _npgHelper.GetColumns(_connection, tableName); foreach (int trendTagId in _trendTagIds) { string column = GetColumnName(trendTagId); if (columns.Contains(column)) { continue; } NpgQuery createColumnQuery = _npgQueryHelper.CreateColumn( tableName, new NpgColumnInfo { Name = column, DataType = NpgDataType.Float8, NotNull = false }); _npgHelper.ExecuteNonQuery(_connection, createColumnQuery); } }
public void EnsureTable(NpgsqlConnection connection) { var tables = _npgHelper.GetTables(connection); if (tables.Contains(_tableName)) { return; } var tb = new NpgTableInfoBuilder(_tableName); tb.AddColumn(DbStr.Time, NpgDataType.Int8, true); tb.AddColumn(DbStr.Text, NpgDataType.Text); tb.AddColumn(DbStr.Bytes, NpgDataType.Bytea); tb.AddPrimaryKey(DbStr.Time); var createTableQuery = _npgQueryHelper.CreateTable(tb.Build()); _npgHelper.ExecuteScript(connection, new[] { createTableQuery }); }
public void EnsureTable(NpgsqlConnection connection) { var tables = _npgHelper.GetTables(connection); if (tables.Contains(_tableName)) { return; } var tb = new NpgTableInfoBuilder(_tableName); tb.AddColumn(DbStr.StartTime, NpgDataType.Int8, true); tb.AddColumn(DbStr.AlarmId, NpgDataType.Int4, true); tb.AddColumn(DbStr.EndTime, NpgDataType.Int8); tb.AddColumn(DbStr.AcknowledgeTime, NpgDataType.Int8); tb.AddColumn(DbStr.UserId, NpgDataType.Int8); tb.AddPrimaryKey(DbStr.StartTime); tb.AddPrimaryKey(DbStr.AlarmId); var createTableQuery = _npgQueryHelper.CreateTable(tb.Build()); var createEndTimeIndexQuery = _npgQueryHelper.CreateIndex(_tableName, columns: DbStr.EndTime); var createAckTimeIndexQuery = _npgQueryHelper.CreateIndex(_tableName, columns: DbStr.AcknowledgeTime); _npgHelper.ExecuteScript(connection, new[] { createTableQuery, createEndTimeIndexQuery, createAckTimeIndexQuery }); }