mirror of
https://github.com/jackfoxy/urQL.git
synced 2024-09-11 11:55:33 +03:00
alter table
This commit is contained in:
parent
3f139a3a1b
commit
7c3d5a724f
@ -36,15 +36,15 @@ TBD
|
||||
|
||||
```
|
||||
ALTER TABLE [ <db-qualifer> ]{ <table-name> }
|
||||
{ ALTER COLUMN { <column-name> <aura> } [ ,... n
|
||||
| ADD COLUMN { <column-name> <aura> } [ ,... n ]
|
||||
| DROP COLUMN { <column-name> } [ ,... n ]
|
||||
{ ALTER COLUMN ( { <column-name> <aura> } [ ,... n ] )
|
||||
| ADD COLUMN ( { <column-name> <aura> } [ ,... n ] )
|
||||
| DROP COLUMN ( { <column-name> } [ ,... n ] )
|
||||
| ADD FOREIGN KEY <foreign-key-name> (<column-name> [ ,... n ])
|
||||
REFERENCES [<namespace-name>.]<table-name> ( <column-name> [ ,... n ])
|
||||
[ ON DELETE { NO ACTION | CASCADE } ]
|
||||
[ ON UPDATE { NO ACTION | CASCADE } ]
|
||||
[ ,... n ]
|
||||
| DROP FOREIGN KEY <foreign-key-name> [ ,... n ] }
|
||||
| DROP FOREIGN KEY ( <foreign-key-name> [ ,... n ] } )
|
||||
```
|
||||
|
||||
Example:
|
||||
|
@ -582,7 +582,7 @@
|
||||
script q.q.u.+3.q:table-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ ~ ~) commands]
|
||||
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ ~ +>.parsed) commands]
|
||||
==
|
||||
!!
|
||||
%create-database
|
||||
|
@ -54,6 +54,19 @@
|
||||
column=@t
|
||||
alias=@t
|
||||
==
|
||||
+$ foreign-key
|
||||
$:
|
||||
%foreign-key
|
||||
name=@t
|
||||
table=qualified-object
|
||||
columns=(list ordered-column) :: the source columns
|
||||
reference-table=qualified-object :: reference (target) table
|
||||
reference-columns=(list @t) :: and columns
|
||||
referential-integrity=(list referential-integrity-action) :: what to do when referenced item deletes or updates
|
||||
==
|
||||
::
|
||||
:: expressions
|
||||
::
|
||||
:: { = | <> | != | > | >= | !> | < | <= | !< }
|
||||
+$ binary-operator @tas
|
||||
+$ binary-predicate $:(* binary-operator *)
|
||||
@ -236,17 +249,6 @@
|
||||
columns=(list ordered-column)
|
||||
==
|
||||
+$ create-namespace $:([%create-namespace database-name=@t name=@t])
|
||||
|
||||
+$ foreign-key
|
||||
$:
|
||||
%foreign-key
|
||||
name=@t
|
||||
table=qualified-object
|
||||
columns=(list ordered-column) :: the source columns
|
||||
reference-table=qualified-object :: reference (target) table
|
||||
reference-columns=(list @t) :: and columns
|
||||
referential-integrity=(list referential-integrity-action) :: what to do when referenced item deletes or updates
|
||||
==
|
||||
+$ create-table
|
||||
$:
|
||||
%create-table
|
||||
|
@ -136,27 +136,31 @@
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') urql)
|
||||
::
|
||||
::
|
||||
::++ test-alter-table-
|
||||
:: =/ expected
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') "")
|
||||
:: drop 2 foreign keys, extra spaces
|
||||
++ test-alter-table-7
|
||||
=/ expected [%alter-table table=[%qualified-object ship=~ database='db1' namespace='dbo' name='mytable'] alter-columns=~ add-columns=~ drop-columns=~ add-foreign-keys=~ drop-foreign-keys=['fk1' 'fk2' ~]]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') " ALTER TABLE mytable DROP FOREIGN KEY ( fk1, fk2 )")
|
||||
::
|
||||
::
|
||||
::++ test-alter-table-
|
||||
:: =/ expected
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') "")
|
||||
:: drop 2 foreign keys, no extra spaces
|
||||
++ test-alter-table-8
|
||||
=/ expected [%alter-table table=[%qualified-object ship=~ database='db' namespace='dbo' name='mytable'] alter-columns=~ add-columns=~ drop-columns=~ add-foreign-keys=~ drop-foreign-keys=['fk1' 'fk2' ~]]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER TABLE db..mytable DROP FOREIGN KEY (fk1,fk2)")
|
||||
::
|
||||
::
|
||||
::++ test-alter-table-
|
||||
:: =/ expected
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') "")
|
||||
|
||||
:: drop 1 foreign key
|
||||
++ test-alter-table-9
|
||||
=/ expected [%alter-table table=[%qualified-object ship=~ database='db1' namespace='ns' name='mytable'] alter-columns=~ add-columns=~ drop-columns=~ add-foreign-keys=~ drop-foreign-keys=['fk1' ~]]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER TABLE ns.mytable DROP FOREIGN KEY (fk1)")
|
||||
::
|
||||
:: fail when table name not a term
|
||||
++ test-fail-alter-table-10
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'db1') "ALTER TABLE ns.myTable DROP FOREIGN KEY (fk1)")
|
||||
::
|
||||
:: create database
|
||||
::
|
||||
@ -173,12 +177,12 @@
|
||||
!> (parse:parse(current-database 'dummy') "cReate datAbase \0a my-database; cReate namesPace my-db.another-namespace")
|
||||
::
|
||||
:: fail when database name is not a term
|
||||
++ test-create-database-3
|
||||
++ test-fail-create-database-3
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'dummy') "cReate datAbase My-database")
|
||||
::
|
||||
:: fail when commands are prior to create database
|
||||
++ test-create-database-4
|
||||
++ test-fail-create-database-4
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'dummy') "create namespace my-namespace ; cReate datAbase my-database")
|
||||
::
|
||||
@ -487,7 +491,7 @@
|
||||
|. (parse:parse(current-database 'other-db') "DROP table Db.ns.name")
|
||||
::
|
||||
:: fail when namespace qualifier is not a term
|
||||
++ test-drop-table-9
|
||||
++ test-fail-drop-table-9
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'other-db') "DROP table db.nS.name")
|
||||
::
|
||||
|
Loading…
Reference in New Issue
Block a user