squeal
squeal copied to clipboard
Track columns/tables referred to by views
Postgres will give you a runtime error if you remove or alter a column or table that is currently in use by a view. Squeal currently does not track that information and thus will have the same runtime error. It would be useful to track that information so that we could alert the user that the view is no longer valid.
Here is an example of code that would be invalid in postgres but not in squeal:
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedLabels #-}
module Main where
import Squeal.PostgreSQL
type ExampleTable = 'Table ('[] :=> '[ "id" ::: 'NoDef :=> 'NotNull 'PGint4 ])
type ExampleView = 'View '[ "id" ::: 'NotNull 'PGint8 ]
type Schemas = '[ "public" ::: '[ "example" ::: ExampleTable, "view" ::: ExampleView ] ]
migration :: Definition '[ "public" ::: '[] ] Schemas
migration =
createTable #example (notNullable int8 `as` #id) Nil
>>>
createView #view (select_ #id (from (table #example)))
>>>
alterTable #example (alterColumn #id (alterType (notNullable int4)))