Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing index actions #17

Open
alexfmpe opened this issue Mar 11, 2021 · 1 comment
Open

Missing index actions #17

alexfmpe opened this issue Mar 11, 2021 · 1 comment

Comments

@alexfmpe
Copy link
Contributor

does not currently represent creating/dropping an index (though it does for constraints)

@jrpotter
Copy link
Contributor

jrpotter commented May 9, 2022

I ended up getting confused as to how to properly do this as well. I tried a couple of different things, including somehow tracking migrations in the same way beam-migrate, but at the end of it, I used the following snippet and manually added indices after running any automatically created migrations:

createIndex
  :: forall be db tbl ty
   . Beamable tbl
  => DatabaseEntity be db (TableEntity tbl)
  -> (TableSettings tbl -> TableField tbl ty)
  -> PgCommandSyntax
createIndex table column =
  let tName = table ^. dbEntityDescriptor . dbEntityName
      settings = dbTableSettings $ table ^. dbEntityDescriptor
      cName = column settings ^. fieldName
   in PgCommandSyntax PgCommandTypeDdl $ emit $ T.encodeUtf8
        ( "CREATE INDEX IF NOT EXISTS " <> sqlEscaped (tName <> "_" <> cName) <>
          " ON " <> sqlEscaped tName <> " (" <> sqlEscaped cName <> ");\n"
        )

Doesn't feel like the right solution but a potential workaround until something better makes its way upstream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants