Skip to content

Commit

Permalink
Adjust available checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gjeck committed Jan 24, 2020
1 parent 538252a commit 09087bd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
16 changes: 15 additions & 1 deletion GRDB/QueryInterface/Schema/TableDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,21 @@ public final class TableAlteration {
return column
}

#if !os(OSX) || GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE
/// Renames a column in a table.
///
/// try db.alter(table: "player") { t in
/// t.rename(column: "url", to: "home_url")
/// }
///
/// See https://www.sqlite.org/lang_altertable.html
///
/// - parameter name: the column name to rename.
/// - parameter newName: the new name of the column.
public func rename(column name: String, to newName: String) {
alterations.append(.rename(old: name, new: newName))
}
#elseif !os(OSX)
/// Renames a column in a table.
///
/// try db.alter(table: "player") { t in
Expand Down
22 changes: 21 additions & 1 deletion Tests/GRDBTests/TableDefinitionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,27 @@ class TableDefinitionTests: GRDBTestCase {
}
}

#if !os(OSX) || GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE
func testAlterTableRenameColumn() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "test") { t in
t.column("a", .text)
}

sqlQueries.removeAll()
try db.alter(table: "test") { t in
t.rename(column: "a", to: "b")
t.add(column: "c")
t.rename(column: "c", to: "d")
}

assertEqualSQL(sqlQueries[sqlQueries.count - 3], "ALTER TABLE \"test\" RENAME COLUMN \"a\" TO \"b\"")
assertEqualSQL(sqlQueries[sqlQueries.count - 2], "ALTER TABLE \"test\" ADD COLUMN \"c\"")
assertEqualSQL(sqlQueries[sqlQueries.count - 1], "ALTER TABLE \"test\" RENAME COLUMN \"c\" TO \"d\"")
}
}
#elseif !os(OSX)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
func testAlterTableRenameColumn() throws {
let dbQueue = try makeDatabaseQueue()
Expand Down

0 comments on commit 09087bd

Please sign in to comment.