Make support for "after column"
Closed this issue · 2 comments
Casperhr commented
Missing feature
ALTER TABLE `listings` ADD `client_id` INT NULL DEFAULT NULL AFTER `object_no`;
tanner0101 commented
Looks neither SQLite or PostgreSQL actually support this. Should probably be added using the DatabaseSchema storage and specific extensions on SchemaBuilder where database type is MySQL.
tanner0101 commented
Had to get this one done before it turned a year old ;)
CustomOrder.swift
struct CustomOrder: MySQLModel {
var id: Int?
var a: Int
var b: Int
}
CreateCustomOrder.swift
struct CreateCustomOrder: MySQLMigration {
static func prepare(on conn: MySQLConnection) -> Future<Void> {
return MySQLDatabase.create(CustomOrder.self, on: conn) { builder in
builder.field(for: \.id)
builder.field(for: \.a)
}
}
static func revert(on conn: MySQLConnection) -> Future<Void> {
return MySQLDatabase.delete(CustomOrder.self, on: conn)
}
}
struct AddColumnBToCustomOrder: MySQLMigration {
static func prepare(on conn: MySQLConnection) -> Future<Void> {
return MySQLDatabase.update(CustomOrder.self, on: conn) { builder in
builder.field(for: \.b)
builder.order(\.b, after: \.id)
}
}
static func revert(on conn: MySQLConnection) -> Future<Void> {
return MySQLDatabase.update(CustomOrder.self, on: conn) { builder in
builder.deleteField(for: \.b)
}
}
}
This will be available in 3.0.0 RC 4.1