mirror of https://github.com/vapor/docs.git
875 B
875 B
PostgreSQL Schema Builder
Fluent lets you customize your schemas with PostgreSQL-specific column types. You can even set default values. Let's take a look at creating a simple Planet model with custom PostgreSQL field tpyes.
/// Type of planet.
enum PlanetType: String, Codable, CaseIterable, ReflectionDecodable {
case smallRocky
case gasGiant
case dwarf
}
/// Represents a planet.
struct Planet: PostgreSQLModel, PostgreSQLMigration {
/// Unique identifier.
var id: Int?
/// Name of the planet.
let name: String
/// Planet's specific type.
let type: PlanetType
}
The above model looks great, but there are a couple of problems with the automatically generated migration:
nameuses aTEXTcolumn, but we want to useVARCHAR(64).typeis defaulting to aJSONBcolumn, but we want to store it asENUM().