valderman / selda

A type-safe, high-level SQL library for Haskell
https://selda.link
MIT License
478 stars 58 forks source link

Migration: validation against schema fails with SQLite with tables that contain UUID columns #180

Open YPares opened 1 year ago

YPares commented 1 year ago

With selda-sqlite (v0.5.2.0), I'm getting errors with this kind of setup:

migrateUuidTableTest = do
  tryDropTable migrationUuid1
  createTable migrationUuid1
  insert_ migrationUuid1 [Only nil]
  autoMigrate False stepsUuid
  res <- query $ do
    select migrationUuid2
  assEq "migration went wrong" [nil] (fmap snd res)

migrationUuid1 :: Table (Only UUID)
migrationUuid1 = table "tableUuid" [Single mtUuid1_1 :- primary]
mtUuid1_1 = selectors migrationUuid1

migrationUuid2 :: Table (Text, UUID)
migrationUuid2 = table "tableUuid" [Single mtUuid2_1 :- primary]
mtUuid2_1 :*: mtUuid2_2 = selectors migrationUuid2

stepsUuid =
  [ [] --- AAA
  , [Migration migrationUuid1 migrationUuid2 $ \foo -> pure $ new
      [ mtUuid2_1 := toString (the foo)
      , mtUuid2_2 := the foo
      ]
    ]
  ] 

Depending on whether the AAA line above is there or not, I'm getting either

ValidationError "error validating table \"tableUuid\":\ntable has inconsistent columns:\n  \"col_0\":\n    column should have type `TUUID', but actually has type `TBlob' in database\n"

or just

ValidationError "no starting state matches the current state of the database"

but both seem to point at a problem re. how selda-sqlite deals with UUIDs when validating the schemas.

YPares commented 1 year ago

I opened an MR with a new test that exhibits that: https://github.com/valderman/selda/pull/181