public override void Up()
 {
     TableSchema.Table t = CreateTable("Test1");
     t.AddColumn("Name", DbType.String, 50);
     t.AddColumn("Description", DbType.String, 100);
     t.AddColumn("DateEntered", DbType.DateTime, 0, false, "getdate()");
 }
Beispiel #2
0
 /// <summary>
 /// Adds the SubSonic state columns.
 /// </summary>
 /// <param name="table">The table to which the columns will be added.</param>
 public void AddSubSonicStateColumns(TableSchema.Table table)
 {
     table.AddColumn(ReservedColumnName.CREATED_ON, DbType.DateTime, 0, false, "getdate()");
     table.AddColumn(ReservedColumnName.MODIFIED_ON, DbType.DateTime, 0, false, "getdate()");
     table.AddColumn(ReservedColumnName.CREATED_BY, DbType.String);
     table.AddColumn(ReservedColumnName.MODIFIED_BY, DbType.String);
 }
Beispiel #3
0
            public override void Up()
            {
                TableSchema.Table table = CreateTable("Distribution");
                table.AddPrimaryKeyColumn("Id");
                table.AddColumn("Name", DbType.String, 20);
                table.AddColumn("Capacity", DbType.Int32);

                table = CreateTable("ShipStatus");
                table.AddColumn("Status", DbType.String, 50);
                table.AddColumn("Code", DbType.String, 4);
                AddSubSonicStateColumns(table);
            }
        public void Create_Table()
        {
            TableSchema.Table testSchema = new TableSchema.Table("Southwind", "ShippingCarriers");
            testSchema.AddPrimaryKeyColumn("Id");
            testSchema.AddColumn("Name", DbType.String, 50, false);
            testSchema.AddColumn("Description", DbType.String, 100, false);

            ISqlGenerator generator = new MySqlGenerator(null);
            string        sql       = generator.BuildCreateTableStatement(testSchema);

            Assert.AreEqual(
                "CREATE TABLE `ShippingCarriers` (\r\n  `Id` INTEGER NOT NULL AUTO_INCREMENT,\r\n  `Name` nvarchar(50) NOT NULL,\r\n  `Description` nvarchar(100) NOT NULL,\r\n  PRIMARY KEY (`Id`) \r\n)",
                sql);
        }
Beispiel #5
0
 public override void Up()
 {
     TableSchema.Table       tb  = this.CreateTable("MyTb");
     TableSchema.TableColumn col = new TableSchema.TableColumn(tb);
     col.ColumnName   = "Id";
     col.DataType     = System.Data.DbType.AnsiStringFixedLength;
     col.MaxLength    = 3;
     col.IsPrimaryKey = true;
     tb.AddColumn(col);
 }
Beispiel #6
0
 /// <summary>
 /// Adds the column.
 /// </summary>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="columnName">Name of the column to add.</param>
 /// <param name="dbType">Type of the db.</param>
 /// <param name="length">The length.</param>
 /// <param name="nullable">if set to <c>true</c> [nullable].</param>
 /// <param name="defaultValue">The default value.</param>
 public void AddColumn(string tableName, string columnName, DbType dbType, int length, bool nullable, string defaultValue)
 {
     TableSchema.Table table = Provider.GetTableSchema(tableName, TableType.Table);
     if (table == null)
     {
         throw new ArgumentException("Unknown table name " + tableName);
     }
     table.AddColumn(columnName, dbType, length, nullable, defaultValue);
     TableSchema.TableColumn column = table.GetColumn(columnName);
     AddMigrationStep(MigrationStepType.AddColumn, table, column);
 }
Beispiel #7
0
        private static void CreateSchemaInfo(string providerName)
        {
            TableSchema.Table tbl = new TableSchema.Table(providerName, SCHEMA_INFO);
            tbl.AddColumn("version", DbType.Int32, 0, false, "0");

            ISqlGenerator generator = DataService.GetGenerator(providerName);
            string        sql       = generator.BuildCreateTableStatement(tbl);

            DataService.ExecuteQuery(new QueryCommand(sql, providerName));
            DataService.Providers[providerName].ReloadSchema();
        }
Beispiel #8
0
        public void Dual_ForeignKey_Relationships_ShouldBe_Possible_From_One_To_Many()
        {
            //load em
            using (Migration m = new Migration("Northwind")) {
                TableSchema.Table one_table = m.CreateTableWithKey("One");

                TableSchema.Table many_table = m.CreateTableWithKey("ManyTable");
                many_table.AddColumn("first_reference_to_table_one", System.Data.DbType.Int32);
                many_table.AddColumn("second_reference_to_table_one", System.Data.DbType.Int32);

                m.CreateForeignKey(one_table.GetColumn("Id"), many_table.GetColumn("first_reference_to_table_one"));
                m.CreateForeignKey(one_table.GetColumn("Id"), many_table.GetColumn("second_reference_to_table_one"));
            }

            DataService.ClearSchemaCache("Northwind");

            //drop em
            using (Migration m = new Migration("Northwind")) {
                m.DropTable("ManyTable");
                m.DropTable("One");
            }
        }
Beispiel #9
0
        public void MigrationOnDispose()
        {
            //testing Rob's super-cool migration on dispose pattern
            using (Migration m = new Migration("Northwind"))
            {
                TableSchema.Table t = m.CreateTable("DisposeTable");
                t.AddPrimaryKeyColumn();
                t.AddColumn("Name", DbType.String);
                m.AddSubSonicStateColumns(t);
            }

            DataService.ClearSchemaCache("Northwind");
            TableSchema.Table table = DataService.GetSchema("DisposeTable", "Northwind");
            Assert.IsNotNull(table);
        }
Beispiel #10
0
            public override void Up()
            {
                TableSchema.Table table = CreateTable("Distribution");
                table.AddColumn("Name", DbType.String, 20);
                table.AddColumn("Capacity", DbType.Int32);

                table = CreateTable("ShipStatus");
                table.AddColumn("Status", DbType.String, 50);
                table.AddColumn("Code", DbType.String, 4);
                AddSubSonicStateColumns(table);

                //this should cause the migration to fail, the previous two tables
                //shouldn't end up in the db
                table = CreateTable("Products");
                table.AddColumn("ID", DbType.Int32);
                table.AddColumn("Name", DbType.String, 40);
            }
Beispiel #11
0
        public void CreateTable_Should_Allow_Char3_As_PrimaryKey()
        {
            new InlineQuery("Northwind").Execute("IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyTb]') AND type in (N'U')) \r\n DROP TABLE [dbo].[MyTb]");


            using (Migration m = new Migration("Northwind")) {
                TableSchema.Table       tb  = m.CreateTable("MyTb");
                TableSchema.TableColumn col = new TableSchema.TableColumn(tb);
                col.ColumnName   = "Id";
                col.DataType     = System.Data.DbType.AnsiStringFixedLength;
                col.MaxLength    = 3;
                col.IsPrimaryKey = true;
                tb.AddColumn(col);
            }


            //pull the table out
            DataService.ClearSchemaCache("Northwind");
            TableSchema.Table table = DataService.GetSchema("MyTb", "Northwind");

            Assert.IsNotNull(table);
            Assert.AreEqual(3, table.PrimaryKey.MaxLength);
        }