You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a migration in which I have added a CreateIndexes() method, which is executed when runner.MigrateUp();
I would like to know if I can call only the CreateIndexes() method of all migrations without executing runner.MigrateUp(), with the object of being able to recreate the indexes if necessary without having to touch the table.
Something like this, a little help would be very welcome
public static void GetMigrationList()
{
var serviceProvider = CreateServices();
var runner = serviceProvider.GetRequiredService<IMigrationRunner>();
var migrations = GetMigrations(runner);
foreach (var migration in migrations)
{
var mig = Activator.CreateInstance(migration.Value.Migration.GetType());
mig.CreateIndexes();
}
}
Test Migration
[Migration(202410011)]
public class DBS_10011_Logs : Migration
{
const string _tableName = "logs_data";
public override void Up()
{
if (Schema.Table(_tableName).Exists()) return;
Create.Table(_tableName)
.WithColumn("Id").AsInt32().PrimaryKey().Identity()
.WithColumn("Data").AsDateTime().NotNullable().WithDefaultValue(SystemMethods.CurrentDateTime)
.WithColumn("Utilizador").AsString(128).NotNullable()
.WithColumn("Desig").AsString(128).Nullable()
.WithColumn("Tabela").AsString(50).Nullable()
.WithColumn("Comando").AsString(1).Nullable();
CreateIndexes();
}
public override void Down()
{
Delete.Table(_tableName);
}
public void CreateIndexes()
{
if (Schema.Table(_tableName).Index("ix_logs_data_user").Exists())
Delete.Index("ix_logs_data_user").OnTable(_tableName).OnColumn("User");
Create.Index("ix_logs_data_user")
.OnTable(_tableName).InSchema("dbo")
.OnColumn("User").Ascending();
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a migration in which I have added a CreateIndexes() method, which is executed when runner.MigrateUp();
I would like to know if I can call only the CreateIndexes() method of all migrations without executing runner.MigrateUp(), with the object of being able to recreate the indexes if necessary without having to touch the table.
Something like this, a little help would be very welcome
Test Migration
Beta Was this translation helpful? Give feedback.
All reactions