Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions beam-core/Database/Beam/Schema/Tables.hs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ instance Beamable tbl => IsDatabaseEntity be (TableEntity tbl) where
dbEntityName f tbl = fmap (\t' -> tbl { dbTableCurrentName = t' }) (f (dbTableCurrentName tbl))
dbEntitySchema f tbl = fmap (\s' -> tbl { dbTableSchema = s'}) (f (dbTableSchema tbl))
dbEntityAuto nm =
DatabaseTable Nothing nm (unCamelCaseSel nm) defTblFieldSettings
DatabaseTable Nothing nm nm defTblFieldSettings

instance Beamable tbl => RenamableWithRule (FieldRenamer (DatabaseEntityDescriptor be (ViewEntity tbl))) where
renamingFields renamer =
Expand Down Expand Up @@ -847,7 +847,7 @@ instance Selector f =>
GDefaultTableFieldSettings (S1 f (K1 Generic.R (TableField table field)) p) where
gDefTblFieldSettings (_ :: Proxy (S1 f (K1 Generic.R (TableField table field)) p)) = M1 (K1 s)
where s = TableField (pure rawSelName) name
name = unCamelCaseSel rawSelName
name = T.dropWhile (=='_') rawSelName
rawSelName = T.pack (selName (undefined :: S1 f (K1 Generic.R (TableField table field)) ()))

instance ( TypeError ('Text "All Beamable types must be record types, so appropriate names can be given to columns")) => GDefaultTableFieldSettings (K1 r f p) where
Expand Down
20 changes: 11 additions & 9 deletions beam-migrate/Database/Beam/Migrate/Generics/Tables.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ instance (BeamMigrateSqlBackend be, HasDefaultSqlDataType be ty) =>
-- TODO Not sure if individual databases will want to customize these types


#if WORD_SIZE_IN_BITS == 32
-- #if WORD_SIZE_IN_BITS == 32
-- instance BeamMigrateSqlBackend be => HasDefaultSqlDataType be Int where
-- defaultSqlDataType _ = defaultSqlDataType (Proxy @Int32)
-- #elif WORD_SIZE_IN_BITS == 64
-- instance ( BeamMigrateSqlBackend be, BeamSqlT071Backend be ) => HasDefaultSqlDataType be Int where
-- defaultSqlDataType _ = defaultSqlDataType (Proxy @Int64)
-- #else
-- #error "Unsupported word size; check the value of WORD_SIZE_IN_BITS"
-- #endif
instance BeamMigrateSqlBackend be => HasDefaultSqlDataType be Int where
defaultSqlDataType _ = defaultSqlDataType (Proxy @Int32)
#elif WORD_SIZE_IN_BITS == 64
instance ( BeamMigrateSqlBackend be, BeamSqlT071Backend be ) => HasDefaultSqlDataType be Int where
defaultSqlDataType _ = defaultSqlDataType (Proxy @Int64)
#else
#error "Unsupported word size; check the value of WORD_SIZE_IN_BITS"
#endif
defaultSqlDataType _ _ _ = intType

instance BeamMigrateSqlBackend be => HasDefaultSqlDataType be Int32 where
defaultSqlDataType _ _ _ = intType
Expand Down Expand Up @@ -174,7 +176,7 @@ instance BeamMigrateSqlBackend be => HasDefaultSqlDataType be Double where
defaultSqlDataType _ _ _ = doubleType

instance BeamMigrateSqlBackend be => HasDefaultSqlDataType be Scientific where
defaultSqlDataType _ _ _ = numericType (Just (20, Just 10))
defaultSqlDataType _ _ _ = numericType (Just (10, Just 2))

instance BeamMigrateSqlBackend be => HasDefaultSqlDataType be Day where
defaultSqlDataType _ _ _ = dateType
Expand Down
4 changes: 3 additions & 1 deletion beam-postgres/Database/Beam/Postgres/Migrate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module Database.Beam.Postgres.Migrate
, migrateScript
, writeMigrationScript
, pgDataTypeFromAtt
, pgUnknownDataType
, pgEnumerationTypeFromAtt

-- * Postgres data types
, tsquery, tsvector, text, bytea
Expand Down Expand Up @@ -286,7 +288,7 @@ pgDataTypeFromAtt _ oid pgMod
| Pg.typoid Pg.int8 == oid = Just $ pgExpandDataType (Db.bigint :: Db.DataType Postgres Int64)
| Pg.typoid Pg.int4 == oid = Just $ pgExpandDataType (Db.int :: Db.DataType Postgres Int32)
| Pg.typoid Pg.int2 == oid = Just $ pgExpandDataType (Db.smallint :: Db.DataType Postgres Int16)
| Pg.typoid Pg.varchar == oid = Just $ pgExpandDataType (Db.varchar (pgCharLength pgMod))
| Pg.typoid Pg.varchar == oid = Just $ pgExpandDataType (Db.varchar Nothing)
| Pg.typoid Pg.timestamp == oid = Just $ pgExpandDataType Db.timestamp
| Pg.typoid Pg.timestamptz == oid = Just $ pgExpandDataType Db.timestamptz
| Pg.typoid Pg.float8 == oid = Just $ pgExpandDataType Db.double
Expand Down
2 changes: 1 addition & 1 deletion beam-postgres/Database/Beam/Postgres/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ instance HasDefaultSqlDataType Postgres ByteString where
defaultSqlDataType _ _ _ = pgByteaType

instance HasDefaultSqlDataType Postgres LocalTime where
defaultSqlDataType _ _ _ = timestampType Nothing False
defaultSqlDataType _ _ _ = timestampType Nothing True

instance HasDefaultSqlDataType Postgres UTCTime where
defaultSqlDataType _ _ _ = timestampType Nothing True
Expand Down