From 2640c81d81cc57f9388882b1cbf0cce88a8f4fd9 Mon Sep 17 00:00:00 2001 From: Isaac Jacob Date: Fri, 22 Dec 2023 14:21:18 +0530 Subject: [PATCH] changes for compatibility with newton schemas --- beam-core/Database/Beam/Schema/Tables.hs | 4 ++-- .../Database/Beam/Migrate/Generics/Tables.hs | 20 ++++++++++--------- .../Database/Beam/Postgres/Migrate.hs | 4 +++- beam-postgres/Database/Beam/Postgres/Types.hs | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/beam-core/Database/Beam/Schema/Tables.hs b/beam-core/Database/Beam/Schema/Tables.hs index 9cdc7d59e..46ae456dc 100644 --- a/beam-core/Database/Beam/Schema/Tables.hs +++ b/beam-core/Database/Beam/Schema/Tables.hs @@ -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 = @@ -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 diff --git a/beam-migrate/Database/Beam/Migrate/Generics/Tables.hs b/beam-migrate/Database/Beam/Migrate/Generics/Tables.hs index fc0d91b42..5a992b407 100644 --- a/beam-migrate/Database/Beam/Migrate/Generics/Tables.hs +++ b/beam-migrate/Database/Beam/Migrate/Generics/Tables.hs @@ -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 @@ -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 diff --git a/beam-postgres/Database/Beam/Postgres/Migrate.hs b/beam-postgres/Database/Beam/Postgres/Migrate.hs index e23b20659..aa96b7fb7 100644 --- a/beam-postgres/Database/Beam/Postgres/Migrate.hs +++ b/beam-postgres/Database/Beam/Postgres/Migrate.hs @@ -19,6 +19,8 @@ module Database.Beam.Postgres.Migrate , migrateScript , writeMigrationScript , pgDataTypeFromAtt + , pgUnknownDataType + , pgEnumerationTypeFromAtt -- * Postgres data types , tsquery, tsvector, text, bytea @@ -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 diff --git a/beam-postgres/Database/Beam/Postgres/Types.hs b/beam-postgres/Database/Beam/Postgres/Types.hs index 442154d0e..1af69dcae 100644 --- a/beam-postgres/Database/Beam/Postgres/Types.hs +++ b/beam-postgres/Database/Beam/Postgres/Types.hs @@ -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