public void WriteColumnsChanges(TableSchema table) { var mods = table.ModifiedColumns.ChangedColumns; if (mods.Count == 0) return; FillRealTableSchema(table); var writer = new SqlServerCompactColumnWriter(Builder); foreach (var col in mods.Where(c => c.DefaultDropped)) { Builder.AppendFormat("alter table {0} alter column {1} drop default;\n", table.Name, col.Name); } foreach (var col in mods.Where(d => !d.IsDropped)) { Builder.AppendFormat("alter table [{0}] alter column {1} ", table.Name, SqlServerProvider.EscapeIdentifier(col.Current.Name)); writer.Write(col); Builder.AppendLine(";"); } foreach (var cl in mods.Where(c => !string.IsNullOrEmpty(c.DefaultValue))) { Builder.AppendFormat("alter table {0} alter column {1} set default '{2}';\n", table.Name, cl.Name, cl.DefaultValue); } }
public ConstraintsCollection(TableSchema table) { _table = table; Checks = new List<CheckConstraint>(); Uniques = new List<UniqueKeyConstraint>(); ForeignKeys = new List<ForeignKeyConstraint>(); Dropped = new DroppedSchemaItemsCollection(table.Name); }
public override string GenerateCreateTable(TableSchema table) { if (table.Columns.IsIdentityDefined) { var pk=table.Constraints.PrimaryKey; if (pk!=null) pk.Ignore = true; } return base.GenerateCreateTable(table); }
public CreateTableBuilder(DbConnection db, IGenerateDDL generator, TableSchema schema) { _db = db; _generator = generator; _table = schema; _columns = new ColumnsCreator(Table); _constraints = new ConstraintsCreator(Table.Constraints); _indexes = new IndexCreator(Table.Indexes); }
public void Process(TableSchema schema) { _schema = schema; _schema.Name = _ti.Name; _schema.CreationOption = _ti.CreationOptions; ProcessPrimaryKey(); ProcessColumns(); ProcessIndexes(); ProcessForeignKeys(); }
public ModifyTableBuilder(IAccessDb db, IGenerateDDL generator, string name) { _db = db; _generator = generator; name.MustNotBeEmpty(); _table = new TableSchema(name); _columns = new ColumnsEditor(Table, this); _constraints = new ConstraintsEditor(Table.Constraints, this); _indexes = new IndexEditor(Table.Indexes, this); }
public CreateTableBuilder(DbConnection db, IGenerateDDL generator, string tableName, IfTableExists option) { _db = db; _generator = generator; tableName.MustNotBeEmpty(); _table = new TableSchema(tableName); _columns = new ColumnsCreator(Table); _constraints = new ConstraintsCreator(Table.Constraints); _indexes = new IndexCreator(Table.Indexes); Table.Name = tableName; Table.CreationOption = option; }
private void FillRealTableSchema(TableSchema table) { var columns = table.ModifiedColumns.AllColumnsNames; // var tableName = SqlServerProvider.FormatName(table.Name); var all = Db.Query<ColumnSchema>( @"select COLUMN_NAME as ColumnName, DATA_TYPE as DataType , cast (CHARACTER_MAXIMUM_LENGTH as varchar(5))as CharacterMaximumLength, cast (NUMERIC_PRECISION as varchar(5)) as NumericPrecision, cast (NUMERIC_SCALE as varchar(5)) as NumericScale, COLLATION_NAME as CollationName from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @0 and COLUMN_NAME in (@1)", table.Name, columns); foreach (var cs in all) { var column = table.ModifiedColumns[cs.ColumnName]; column.Modifications.Current.Type = ExtractType(cs); column.Modifications.Current.Collation = cs.CollationName; } }
public virtual string GenerateCreateTable(TableSchema table) { _table = table; ColonBeforeConstraints = true; table.Options.Use(_engine); Builder.Clear(); Builder.Append("create table "); WriteTableName(); Builder.Append(" ("); WriteColumns(table.Columns); WriteConstraints(table.Constraints); Builder.Append(")"); WriteEndTableOptions(); WriteIndexes(table.Indexes); return Builder.ToString(); }
public IndexCollection(TableSchema table) { _table = table; Dropped = new DroppedSchemaItemsCollection(table.Name); }
public string GenerateCreateTable(TableSchema table) { throw new NotImplementedException(); }
public string GenerateAlterTable(TableSchema schema) { throw new NotImplementedException(); }
public ColumnsCreator(TableSchema table) { _table = table; }
public override string GenerateAlterTable(TableSchema schema) { throw new NotSupportedException("Sqlite alter table is not supported"); }
public ColumnsEditor(TableSchema table, IModifyTable parent) : base(table) { _table = table; _parent = parent; }
public virtual string GenerateAlterTable(TableSchema schema) { _table = schema; Builder.Clear(); DefineExistingColumns(); WriteColumnRenames(); WriteDroppedIndexes(); WriteDroppedConstraints(); GetChangedColumnsManager().Write(schema.ModifiedColumns); WriteDroppedColumns(); WriteColumnsAdditions(); WriteConstraintsAdditions(); WriteIndexes(Table.Indexes); return Builder.ToString(); }
/// <summary> /// Creates a fluent builder object to help you generate a Create Table script, starting from an existing type. /// You can customize it further /// </summary> /// <returns></returns> public ICreateTable GetCreateTableBuilder <T>() { var schema = new TableSchema(typeof(T)); return(new CreateTableBuilder(Db, GetDDLWriter(), schema)); }