Creation of EF Core Migrations - these execute using EF Tools, but are not integrated to run programmatically
This commit is contained in:
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
|
||||
|
||||
namespace Oqtane.Migrations.Extensions
|
||||
{
|
||||
public static class ColumnsBuilderExtensions
|
||||
{
|
||||
public static OperationBuilder<AddColumnOperation> AddAutoIncrementColumn(this ColumnsBuilder table, string name)
|
||||
{
|
||||
return table.Column<int>(name: name, nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1")
|
||||
.Annotation("Sqlite:Autoincrement", true);
|
||||
}
|
||||
|
||||
public static OperationBuilder<AddColumnOperation> AddBooleanColumn(this ColumnsBuilder table, string name, bool nullable = false)
|
||||
{
|
||||
return table.Column<bool>(name: name, nullable: nullable);
|
||||
}
|
||||
|
||||
public static OperationBuilder<AddColumnOperation> AddDateTimeColumn(this ColumnsBuilder table, string name, bool nullable = false)
|
||||
{
|
||||
return table.Column<DateTime>(name: name, nullable: nullable);
|
||||
}
|
||||
|
||||
public static OperationBuilder<AddColumnOperation> AddDateTimeOffsetColumn(this ColumnsBuilder table, string name, bool nullable = false)
|
||||
{
|
||||
return table.Column<DateTimeOffset>(name: name, nullable: nullable);
|
||||
}
|
||||
|
||||
public static OperationBuilder<AddColumnOperation> AddIntegerColumn(this ColumnsBuilder table, string name, bool nullable = false)
|
||||
{
|
||||
return table.Column<int>(name: name, nullable: nullable);
|
||||
}
|
||||
|
||||
public static OperationBuilder<AddColumnOperation> AddMaxStringColumn(this ColumnsBuilder table, string name, bool nullable = false)
|
||||
{
|
||||
return table.Column<string>(name: name, nullable: nullable);
|
||||
}
|
||||
|
||||
public static OperationBuilder<AddColumnOperation> AddStringColumn(this ColumnsBuilder table, string name, int length, bool nullable = false)
|
||||
{
|
||||
return table.Column<string>(name: name, maxLength: length, nullable: nullable);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
|
||||
namespace Oqtane.Migrations.Extensions
|
||||
{
|
||||
public static class CreateTableBuilderExtensions
|
||||
{
|
||||
public static void AddForeignKey<TEntityBuilder>(this CreateTableBuilder<TEntityBuilder> table, ForeignKey<TEntityBuilder> foreignKey) where TEntityBuilder : BaseEntityBuilder<TEntityBuilder>
|
||||
{
|
||||
table.ForeignKey(
|
||||
name: foreignKey.Name,
|
||||
column: foreignKey.Column,
|
||||
principalTable: foreignKey.PrincipalTable,
|
||||
principalColumn: foreignKey.PrincipalColumn,
|
||||
onDelete: foreignKey.OnDeleteAction);
|
||||
}
|
||||
|
||||
public static void AddPrimaryKey<TEntityBuilder>(this CreateTableBuilder<TEntityBuilder> table, PrimaryKey<TEntityBuilder> primaryKey) where TEntityBuilder : BaseEntityBuilder<TEntityBuilder>
|
||||
{
|
||||
table.PrimaryKey(primaryKey.Name, primaryKey.Columns);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user