On this page
The Migrate method creates the schema specified in the Schema connection string parameter and the schemas specified in ToTable(name, schema) if they don't exist. The migrations history table, __EFMigrationsHistory, is created in the schema specified in the connection string. To use another name or schema for it, call the MigrationsHistoryTable(name, schema) method of the SnowflakeDbContextOptionsBuilder object; this schema is created if it doesn't exist too.
Migrations are supported with the following Snowflake restrictions:
- Every DDL statement in Snowflake commits the current transaction, so migration statements are executed without a transaction. If a migration fails in the middle, the statements that were already executed aren't rolled back. For this reason, the dotnet ef database update command shows warnings that migration operations can't be executed in a transaction. These warnings are expected.
- A change of the column type is generated as ALTER TABLE ... ALTER COLUMN ... SET DATA TYPE. Snowflake itself allows only some type changes, for example, making a text column longer or increasing the precision of a number, and returns an error for other changes.
- ALTER COLUMN can also set or drop NOT NULL, drop the default value, and set a sequence (
sequence.NEXTVAL) as the default value.
- The provider throws NotSupportedException for the following operations: changing an existing column to or from a computed column or changing its expression (drop and add the column instead), setting a default value other than
sequence.NEXTVAL for an existing column, and creating or altering a sequence with a minimum value, a maximum value, or cycling.
- A Snowflake sequence can't be restarted. When the start value of a sequence increases (for example, because HasData seeds a higher key), the migration advances the sequence to the new start value instead. A lower start value leaves the sequence as it is.
- Index operations don't produce any statements, because standard tables have no indexes.
- Comments of tables and columns (HasComment) aren't created or changed: migrations and the EnsureCreated method create tables and columns without comments. To set a comment, add a COMMENT statement to the migration with the Sql method, for example,
migrationBuilder.Sql("COMMENT ON TABLE \"Products\" IS 'Product catalog'");
- When a table is renamed, its sequence is renamed with it, so the key values continue from where they stopped.
- Idempotent migration scripts (for example, the --idempotent option or the GenerateScript method with idempotent scripts) aren't supported. Generate the script from a known migration instead.
- Snowflake has nothing to lock with, so concurrent migrations of one schema aren't guarded.