Skip to content

Commit

Permalink
example compiles successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbecich committed Dec 8, 2024
1 parent 801a842 commit be0b014
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion beam-postgres/examples/src/Pagila/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Database.Beam.Migrate.Types ( CheckedDatabaseSettings, MigrationSteps, un
, evaluateDatabase, migrationStep)
import Database.Beam.Postgres (Postgres, PgCommandSyntax)

migration :: MigrationSteps PgCommandSyntax () (CheckedDatabaseSettings Postgres Pagila.Schema.V0002.PagilaDb)
-- migration :: MigrationSteps PgCommandSyntax () (CheckedDatabaseSettings Postgres Pagila.Schema.V0002.PagilaDb)
migration = migrationStep "Initial commit" V0001.migration >>>
migrationStep "Add film actor, inventory, rental table" V0002.migration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ instance (BeamSqlBackend be, FromBackendRow be T.Text) => FromBackendRow be Ship
-- In this case, we want to store it as the postgres type ``text``
-- Look into the module Database.Beam.Postgres.Syntax for a list of other
-- postgres types that your custom type can take
shippingCarrierType :: DataType PgDataTypeSyntax ShippingCarrier
shippingCarrierType :: DataType Postgres a
shippingCarrierType = DataType pgTextType


Expand Down Expand Up @@ -128,10 +128,11 @@ instance Database Postgres PagilaDb
instance Beamable (PrimaryKey AddressT)
instance Beamable AddressT

lastUpdateField :: TableFieldSchema PgColumnSchemaSyntax LocalTime
lastUpdateField = field "last_update" timestamp (defaultTo_ now_) notNull
-- lastUpdateField :: TableFieldSchema PgColumnSchemaSyntax LocalTime
lastUpdateField :: TableFieldSchema Postgres LocalTime
lastUpdateField = field "last_update" timestamp (defaultTo_ now_) notNull

migration :: () -> Migration PgCommandSyntax (CheckedDatabaseSettings Postgres PagilaDb)
-- migration :: () -> Migration PgCommandSyntax (CheckedDatabaseSettings Postgres PagilaDb)
migration () = do
-- year_ <- createDomain "year" integer (check (\yr -> yr >=. 1901 &&. yr <=. 2155))
PagilaDb <$> createTable "address"
Expand Down
14 changes: 9 additions & 5 deletions beam-postgres/examples/src/Pagila/Schema/V0001.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ data StaffT f
, staffStore :: PrimaryKey StoreT f
, staffActive :: Columnar f Bool
, staffUsername :: Columnar f Text
, staffPassword :: Columnar f ByteString
, staffPassword :: Columnar f Text -- TODO use ByteString
, staffLastUpdate :: Columnar f LocalTime
, staffPicture :: Columnar f (Maybe ByteString)
} deriving Generic
Expand Down Expand Up @@ -326,10 +326,13 @@ instance Beamable FilmCategoryT
instance Beamable (PrimaryKey LanguageT)
instance Beamable LanguageT

lastUpdateField :: TableFieldSchema PgColumnSchemaSyntax LocalTime
createDateField :: TableFieldSchema Postgres LocalTime
createDateField = field "create_date" timestamp (defaultTo_ now_) notNull

lastUpdateField :: TableFieldSchema Postgres LocalTime
lastUpdateField = field "last_update" timestamp (defaultTo_ now_) notNull

migration :: () -> Migration PgCommandSyntax (CheckedDatabaseSettings Postgres PagilaDb)
-- migration :: () -> Migration PgCommandSyntax (CheckedDatabaseSettings Postgres PagilaDb)
migration () = do
-- year_ <- createDomain "year" integer (check (\yr -> yr >=. 1901 &&. yr <=. 2155))
PagilaDb <$> createTable "actor"
Expand Down Expand Up @@ -366,8 +369,9 @@ migration () = do
(field "email" (varchar (Just 50)))
(AddressId (field "address_id" serial notNull))
(field "activebool" boolean (defaultTo_ (val_ True)) notNull)
(field "create_date" date (defaultTo_ now_) notNull)
lastUpdateField)
createDateField
lastUpdateField
)
<*> createTable "film"
(FilmT (field "film_id" smallserial)
(field "title" (varchar (Just 255)) notNull)
Expand Down
4 changes: 2 additions & 2 deletions beam-postgres/examples/src/Pagila/Schema/V0002.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ data PagilaDb f
} deriving Generic
instance Database Postgres PagilaDb

migration :: CheckedDatabaseSettings Postgres V0001.PagilaDb
-> Migration PgCommandSyntax (CheckedDatabaseSettings Postgres PagilaDb)
-- migration :: CheckedDatabaseSettings Postgres V0001.PagilaDb
-- -> Migration PgCommandSyntax (CheckedDatabaseSettings Postgres PagilaDb)
migration oldDb =
PagilaDb
<$> preserve (V0001.actor oldDb)
Expand Down

0 comments on commit be0b014

Please sign in to comment.