New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make support for "after column" #41

Closed
Casperhr opened this Issue Jun 27, 2017 · 2 comments

Comments

2 participants
@Casperhr
Copy link
Member

Casperhr commented Jun 27, 2017

Missing feature

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

@tanner0101 tanner0101 self-assigned this Jul 6, 2017

@tanner0101 tanner0101 added this to the 2.1.0 milestone Jul 6, 2017

@tanner0101 tanner0101 assigned tanner0101 and unassigned tanner0101 Feb 26, 2018

@tanner0101 tanner0101 removed this from the 2.1.0 milestone Mar 27, 2018

@tanner0101

This comment has been minimized.

Copy link
Member

tanner0101 commented Mar 27, 2018

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 tanner0101 added this to the 3.0.0-rc.4.1 milestone Jun 21, 2018

@tanner0101

This comment has been minimized.

Copy link
Member

tanner0101 commented Jun 21, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment