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

Track columns/tables referred to by views #232

Open
SamuelSchlesinger opened this issue May 15, 2020 · 1 comment
Open

Track columns/tables referred to by views #232

SamuelSchlesinger opened this issue May 15, 2020 · 1 comment
Assignees

Comments

@SamuelSchlesinger
Copy link
Collaborator

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
Copy link
Collaborator Author

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

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

No branches or pull requests

2 participants