My Fluent migrator code :
Create.Table("Players")
.WithColumn("Id" ).AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("FirstName").AsString();
Generated SQL is:
CREATE TABLE public.Players (
id serial4 NOT NULL,
"name" varchar(100) NOT NULL,
CONSTRAINT PK_Players PRIMARY KEY (id)
);
But I want the id as GENERATED ALWAYS AS IDENTITY instead of serial4.
Expected table creation SQL is :
CREATE TABLE public.Players (
id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
"name" varchar(100) NOT NULL,
CONSTRAINT "PK_Players" PRIMARY KEY (id)
);
I don't know how to achieve this using fluent migrator.
Could you please provide solutions or suggestions?
Configurations
private static IServiceProvider CreateServices( IConfiguration configuration )
{
return new ServiceCollection()
.AddSingleton<IConventionSet>( new DefaultConventionSet( configuration.GetSection("TenantName").Value, null )
)
.AddFluentMigratorCore()
.ConfigureRunner( r => r
.AddPostgres()
.WithGlobalConnectionString( configuration.GetConnectionString("DefaultConnection" ) )
.WithRunnerConventions( new MigrationRunnerConventions() )
.ScanIn( typeof( Migrations.CoreInitialMigration ).Assembly ).For.Migrations()
)
.BuildServiceProvider(false);
}
private static void UpdateDatabase(IServiceProvider serviceProvider)
{
// Instantiate the runner
var runner = serviceProvider.GetRequiredService<IMigrationRunner>();
// Execute the migrations
runner.MigrateUp();
}
In StartUp.cs
```csharp
var serviceProvider = CreateServices(Configuration);
using (var scope = serviceProvider.CreateScope())
{
UpdateDatabase(scope.ServiceProvider);
}