Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbecich committed Dec 8, 2024
1 parent fcc325c commit dae0101
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion beam-postgres/examples/pagila.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ library
Pagila.Schema.V0001,
Pagila.Schema.V0002,
Pagila.Schema.CustomMigrateExample,
Pagila.Test
Pagila.CompileTimeTest
-- other-modules:
-- other-extensions:
build-depends: base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-}

module Pagila.Test where

import Control.Arrow ()
module Pagila.CompileTimeTest where

import Data.Int ( Int32 )
import Data.Text(Text)

import Database.Beam
( Generic, Beamable, Columnar, Database, Table(..), TableEntity )
import Database.Beam.Postgres
import Database.Beam.Backend.Types ()
import Database.Beam.Postgres ( Postgres )
import Database.Beam.Migrate.Generics
import Database.Beam.Migrate.SQL.SQL92
import Database.Beam.Migrate.Types hiding (migrateScript)
( defaultMigratableDbSettings )
import Database.Beam.Migrate.SQL.SQL92 ( IsSql92DdlCommandSyntax )
import Database.Beam.Migrate.Types ( CheckedDatabaseSettings )

-- compile-time test
data SimpleTbl f
= SimpleTbl
{ simpletblField1 :: Columnar f Int32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,12 @@ instance Database Postgres PagilaDb
instance Beamable (PrimaryKey AddressT)
instance Beamable AddressT

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

migration :: () -> Migration Postgres (CheckedDatabaseSettings Postgres PagilaDb)
migration () = do
-- year_ <- createDomain "year" integer (check (\yr -> yr >=. 1901 &&. yr <=. 2155))
-- year_ <- createDomain "year" integer (check (\yr -> yr >=. 1901 &&. yr <=. 2155))
PagilaDb <$> createTable "address"
(AddressT
(field "address_id" smallserial)
Expand Down
15 changes: 13 additions & 2 deletions beam-postgres/examples/src/Pagila/Schema/V0001.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
{-# LANGUAGE DeriveGeneric #-}

module Pagila.Schema.V0001 where
-- TODO explicit module exports
-- ( FilmT(..), ActorT(..), AddressT, CityT, CountryT, CategoryT, CustomerT
-- , FilmCategoryT, LanguageT, StoreT, StaffT, PagilaDb, ActorId
-- , PrimaryKey(..)
-- , actor, address, city, country, category, customer
-- , film, filmCategory, language, store, staff
-- , lastUpdateField
-- )
-- where

import Database.Beam
( Generic,
Expand Down Expand Up @@ -235,14 +244,16 @@ data FilmT f
, filmLastUpdate :: Columnar f LocalTime
} deriving Generic
type Film = FilmT Identity
deriving instance Eq Film; deriving instance Show Film
deriving instance Eq Film
deriving instance Show Film

instance Table FilmT where
data PrimaryKey FilmT f = FilmId (Columnar f (SqlSerial Int32))
deriving Generic
primaryKey = FilmId . filmId
type FilmId = PrimaryKey FilmT Identity
deriving instance Eq FilmId; deriving instance Show FilmId
deriving instance Eq FilmId
deriving instance Show FilmId

-- Film category

Expand Down
1 change: 0 additions & 1 deletion beam-postgres/examples/src/Pagila/Schema/V0002.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module Pagila.Schema.V0002
( module V0001'
, FilmActorT(..), FilmActor
, PrimaryKey(..), FilmActorId

, migration, PagilaDb
) where

Expand Down

0 comments on commit dae0101

Please sign in to comment.