squeal icon indicating copy to clipboard operation
squeal copied to clipboard

Track columns/tables referred to by views

Open SamuelSchlesinger opened this issue 4 years ago • 1 comments

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.

SamuelSchlesinger avatar May 15 '20 20:05 SamuelSchlesinger

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)))

SamuelSchlesinger avatar May 15 '20 21:05 SamuelSchlesinger