using System;
using FluentMigrator;
namespace ExampleDatabaseMigrations
{
[Migration(2011091900)]
public class ExampleMigration : Migration
{
public override void Up()
{
if (!Schema.Table( "EXAMPLE_TABLE" ).Exists())
{
Create.Table( "EXAMPLE_TABLE" )
.WithColumn( "ID" ).AsInt16().NotNullable().PrimaryKey( "PK_EXAMTABL_ID" )
.WithColumn( "NAME" ).AsAnsiString(100).NotNullable()
.WithColumn( "SHORT_NAME" ).AsAnsiString(50).Nullable()
.WithColumn( "START_DATE" ).AsDate().NotNullable()
.WithColumn( "END_DATE" ).AsDate().Nullable();
Insert.IntoTable( "IDX_EXAMTABL_NAME" )
.Row( new {Id = 1, Name = "TEST" , Start_Date = new DateTime (2011, 9, 19)});
}
if (!Schema.Table( "EXAMPLE_TABLE" ).Index( "IDX_EXAMTABL_NAME" ).Exists())
{
Create.Index( "IDX_EXAMTABL_NAME" )
.OnTable( "EXAMPLE_TABLE" )
.OnColumn( "NAME" ).Ascending();
}
if (!Schema.Table( "EXAMPLE_TABLE" ).Index( "IDX_EXAMTABL_STARDATE_ENDDATE" ).Exists())
{
Create.Index( "IDX_EXAMTABL_STARDATE_ENDDATE" )
.OnTable( "EXAMPLE_TABLE" )
.OnColumn( "START_DATE" ).Ascending()
.OnColumn( "END_DATE" ).Ascending();
}
}
public override void Down()
{
if (Schema.Table( "EXAMPLE_TABLE" ).Exists())
Delete.Table( "EXAMPLE_TABLE" );
}
}
}
* This source code was highlighted with Source Code Highlighter .
using FluentMigrator;
namespace ExampleDatabaseMigrations
{
[Profile( "Example" )]
public class ExampleProfile : Migration
{
public override void Up()
{
//do something
}
public override void Down()
{
//empty, not used
}
}
}
* This source code was highlighted with Source Code Highlighter .
using FluentMigrator.VersionTableInfo;
namespace ExampleDatabaseMigrations
{
[VersionTableMetaData]
public class ExampleVersionInfo : IVersionTableMetaData
{
public string SchemaName { get { return "EXAMPLE_SCHEMA" ; } }
public string TableName { get { return "EXAMPLE_VERSION_TABLE" ; } }
public string ColumnName { get { return "EXAMPLE_VERSION_COLUMN" ; } }
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/129242/