Destructive operations
They are the operations that drop tables, columns, indexes, constraints, and so on.
-
DropColumn(tableName schema.TableName, columnName string, opts ...schema.DropColumnOptions)
-
DropExtension(name string, opts ...schema.DropExtensionOptions)
-
DropIndex(table schema.TableName, columns []string, opts ...schema.DropIndexOptions)
-
DropPrimaryKeyConstraint(tableName schema.TableName, opts ...schema.DropPrimaryKeyConstraintOptions)
-
DropTable(tableName schema.TableName, opts ...schema.DropTableOptions)
-
RenameColumn(tableName schema.TableName, oldColumnName, newColumnName string)
Usually you will use these functions in the down function of a migration, but you can use them in the up function too.
If you want to have the reverse operation of a destructive operation, you can use the reversible options.
Example:
p.DropTable("users", schema.DropTableOptions{
Reversible: &TableOption{
schema.TableName: "users",
PostgresTableDefinition: Innerschema.Tablefunc(t *PostgresTableDef) {
t.Serial("id")
t.String("name")
}),
}})
In that case, if you are in a change function in your migration, the library will at the up operation drop the table users and at the down operation re-create the table users with the columns id and name.