on dev help sign in
fix some more test errors

there's more yet

commit7cf2cc82bb1115782f1f99a549d3fde79b46a018 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 24 Nov 2018, 19:05 (8 years ago) parent186ba63
3 files changed+20−18
squeal-postgresql/src/Squeal/PostgreSQL.hs+3−2 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+11−10 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+6−6
squeal-postgresql/src/Squeal/PostgreSQL.hs+3−2
@@ -37,8 +37,9 @@ type UsersColumns =
3737 , "name" ::: 'NoDef :=> 'NotNull 'PGtext ]
3838type UsersConstraints = '[ "pk_users" ::: 'PrimaryKey '["id"] ]
3939type EmailsColumns =
40− '[ "pk_emails" ::: 'PrimaryKey '["id"]
41− , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"] ]
40+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
41+ , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
42+ , "email" ::: 'NoDef :=> 'Null 'PGtext ]
4243type EmailsConstraints =
4344 '[ "pk_emails" ::: 'PrimaryKey '["id"]
4445 , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"] ]
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+11−10
@@ -153,7 +153,7 @@ type Table = '[] :=>
153153
154154>>> :{
155155let
156− setup :: Definition '[] '["tab" ::: 'Table Table]
156+ setup :: Definition '["public" ::: '[]] '["public" ::: '["tab" ::: 'Table Table]]
157157 setup = createTable #tab
158158 (nullable int `as` #a :* nullable real `as` #b) Nil
159159in printSQL setup
@@ -189,11 +189,11 @@ type Table = '[] :=>
189189 , "b" ::: 'NoDef :=> 'Null 'PGfloat4 ]
190190:}
191191
192−>>> type Schema = '["tab" ::: 'Table Table]
192+>>> type DB = '["public" ::: '["tab" ::: 'Table Table]]
193193
194194>>> :{
195195let
196− setup :: Definition Schema Schema
196+ setup :: Definition DB DB
197197 setup = createTableIfNotExists #tab
198198 (nullable int `as` #a :* nullable real `as` #b) Nil
199199in printSQL setup
@@ -280,7 +280,7 @@ type Schema = '[
280280
281281>>> :{
282282let
283− definition :: Definition '[] Schema
283+ definition :: Definition '["public" ::: '[]] '["public" ::: Schema]
284284 definition = createTable #tab
285285 ( (int & notNullable) `as` #a :*
286286 (int & notNullable) `as` #b )
@@ -315,7 +315,7 @@ type Schema = '[
315315
316316>>> :{
317317let
318− definition :: Definition '[] Schema
318+ definition :: Definition '["public" ::: '[]] '["public" ::: Schema]
319319 definition = createTable #tab
320320 ( (int & nullable) `as` #a :*
321321 (int & nullable) `as` #b )
@@ -345,11 +345,12 @@ type Schema = '[
345345 "id" ::: 'Def :=> 'NotNull 'PGint4,
346346 "name" ::: 'NoDef :=> 'NotNull 'PGtext
347347 ])]
348+type DB = '["public" ::: Schema]
348349:}
349350
350351>>> :{
351352let
352− definition :: Definition '[] Schema
353+ definition :: Definition '["public" ::: '[]] DB
353354 definition = createTable #tab
354355 ( serial `as` #id :*
355356 (text & notNullable) `as` #name )
@@ -395,7 +396,7 @@ type Schema =
395396
396397>>> :{
397398let
398− setup :: Definition '[] Schema
399+ setup :: Definition '["public" ::: '[]] '["public" ::: Schema]
399400 setup =
400401 createTable #users
401402 ( serial `as` #id :*
@@ -430,7 +431,7 @@ type Schema =
430431
431432>>> :{
432433let
433− setup :: Definition '[] Schema
434+ setup :: Definition '["public" ::: '[]] '["public" ::: Schema]
434435 setup =
435436 createTable #employees
436437 ( serial `as` #id :*
@@ -533,7 +534,7 @@ DROP statements
533534--
534535-- >>> :{
535536-- let
536−-- definition :: Definition '["muh_table" ::: 'Table t] '[]
537+-- definition :: Definition '["public" ::: '["muh_table" ::: 'Table t]] '["public" ::: '[]]
537538-- definition = dropTable #muh_table
538539-- :}
539540--
@@ -591,7 +592,7 @@ newtype AlterTable
591592-- let
592593-- definition :: Definition
593594-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
594−-- '["public" ::: '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
595+-- '["public" ::: '["tab" ::: 'Table ('["positive" ::: 'Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
595596-- definition = alterTable #tab (addConstraint #positive (check #col (#col .> 0)))
596597-- in printSQL definition
597598-- :}
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+6−6
@@ -31,7 +31,7 @@ type EmailsTable =
3131
3232>>> :{
3333let
34− makeUsers :: Migration IO '[] '["users" ::: 'Table UsersTable]
34+ makeUsers :: Migration IO '["public" ::: '[]] '["public" ::: '["users" ::: 'Table UsersTable]]
3535 makeUsers = Migration
3636 { name = "make users table"
3737 , up = void . define $
@@ -45,8 +45,8 @@ let
4545
4646>>> :{
4747let
48− makeEmails :: Migration IO '["users" ::: 'Table UsersTable]
49− '["users" ::: 'Table UsersTable, "emails" ::: 'Table EmailsTable]
48+ makeEmails :: Migration IO '["public" ::: '["users" ::: 'Table UsersTable]]
49+ '["public" ::: '["users" ::: 'Table UsersTable, "emails" ::: 'Table EmailsTable]]
5050 makeEmails = Migration
5151 { name = "make emails table"
5252 , up = void . define $
@@ -68,10 +68,10 @@ Now that we have a couple migrations we can chain them together.
6868>>> :{
6969let
7070 numMigrations
71− :: Has "schema_migrations" schema ('Table MigrationsTable)
72− => PQ schema schema IO ()
71+ :: Has "migrations" db MigrationsSchema
72+ => PQ db db IO ()
7373 numMigrations = do
74− result <- runQuery (selectStar (from (table (#schema_migrations `as` #m))))
74+ result <- runQuery (selectStar (from (table (#migrations ! #schema_migrations `as` #m))))
7575 num <- ntuples result
7676 liftBase $ print num
7777:}