vapor/fluent-mysql-driver

Make support for "after column"

Closed this issue · 2 comments

Missing feature

ALTER TABLE `listings` ADD `client_id` INT NULL DEFAULT NULL AFTER `object_no`;

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.

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)
        }
    }
}

screen shot 2018-06-21 at 7 46 52 pm

This will be available in 3.0.0 RC 4.1