Created
March 17, 2018 16:18
-
-
Save kjessup/ee8a46cd03978a184fec6ed0a5650dd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CloudFormation.RDSInstance { | |
func authDb() throws -> Database<PostgresDatabaseConfiguration> { | |
return Database(configuration: try databaseConfiguration(database: biqAuthDatabaseName)) | |
} | |
func databaseConfiguration() throws -> PostgresDatabaseConfiguration { | |
return try databaseConfiguration(database: biqAuthDatabaseName) | |
} | |
func databaseConfiguration(database: String) throws -> PostgresDatabaseConfiguration { | |
return try .init(database: database, host: hostName, port: hostPort, username: userName, password: password) | |
} | |
func initBiqDatabase() throws { | |
do { | |
let postgresConfig = try databaseConfiguration(database: "postgres") | |
let db = Database(configuration: postgresConfig) | |
struct PGDatabase: Codable, TableNameProvider { | |
static var tableName = "pg_database" | |
let datname: String | |
} | |
let count = try db.table(PGDatabase.self).where(\PGDatabase.datname == biqAuthDatabaseName).count() | |
if count == 0 { | |
try db.sql("CREATE DATABASE \(biqAuthDatabaseName)") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment