mirror of
https://github.com/jackfoxy/urQL.git
synced 2024-09-11 11:55:33 +03:00
fix alter index; start alter table
This commit is contained in:
parent
8061cd748f
commit
b59ff55c99
@ -7,6 +7,7 @@
|
||||
$%
|
||||
alter-index:ast
|
||||
alter-namespace:ast
|
||||
alter-table:ast
|
||||
create-database:ast
|
||||
create-index:ast
|
||||
create-namespace:ast
|
||||
@ -26,6 +27,7 @@
|
||||
$%
|
||||
%alter-index
|
||||
%alter-namespace
|
||||
%alter-table
|
||||
%create-database
|
||||
%create-index
|
||||
%create-namespace
|
||||
@ -341,11 +343,32 @@
|
||||
;~(plug foreign-key (cook cook-referential-integrity referential-integrity))
|
||||
foreign-key
|
||||
==
|
||||
++ column-definitions ~+ ;~(pfix whitespace (ifix [pal par] column-defintion-list))
|
||||
++ alter-columns ~+ ;~ plug
|
||||
(cold %alter-column ;~(plug whitespace (jester 'alter') whitespace (jester 'column')))
|
||||
column-definitions
|
||||
==
|
||||
++ add-columns ~+ ;~ plug
|
||||
(cold %add-column ;~(plug whitespace (jester 'add') whitespace (jester 'column')))
|
||||
column-definitions
|
||||
==
|
||||
++ drop-columns ~+ ;~ plug
|
||||
(cold %drop-column ;~(plug whitespace (jester 'drop') whitespace (jester 'column')))
|
||||
face-list
|
||||
==
|
||||
++ add-foreign-key ~+ ;~ plug
|
||||
(cold %add-fk ;~(plug whitespace (jester 'add')))
|
||||
(more com full-foreign-key)
|
||||
==
|
||||
++ drop-foreign-key ~+ ;~ plug
|
||||
(cold %drop-fk ;~(plug whitespace (jester 'drop') whitespace (jester 'foreign') whitespace (jester 'key')))
|
||||
face-list
|
||||
==
|
||||
::
|
||||
:: parse urQL command
|
||||
::
|
||||
++ parse-alter-index
|
||||
=/ columns ;~(sfix ordered-column-list end-or-next-command)
|
||||
=/ columns ;~(pfix whitespace ordered-column-list)
|
||||
=/ action ;~(pfix whitespace ;~(pose (jester 'rebuild') (jester 'disable') (jester 'resume')))
|
||||
;~ plug
|
||||
;~(pfix whitespace parse-qualified-3object)
|
||||
@ -357,6 +380,10 @@
|
||||
;~(pfix ;~(plug whitespace (jester 'transfer')) ;~(pfix whitespace ;~(pose (jester 'table') (jester 'view'))))
|
||||
;~(sfix ;~(pfix whitespace parse-qualified-3object) end-or-next-command)
|
||||
==
|
||||
++ parse-alter-table ;~ plug
|
||||
;~(pfix whitespace parse-qualified-3object)
|
||||
;~(sfix ;~(pfix whitespace ;~(pose alter-columns add-columns drop-columns add-foreign-key drop-foreign-key)) end-or-next-command)
|
||||
==
|
||||
++ parse-create-namespace ;~ sfix
|
||||
parse-qualified-2-name
|
||||
end-or-next-command
|
||||
@ -379,7 +406,7 @@
|
||||
:: table name
|
||||
;~(pfix whitespace parse-qualified-3object)
|
||||
:: column defintions
|
||||
;~(pfix whitespace (ifix [pal par] column-defintion-list))
|
||||
column-definitions
|
||||
:: primary key
|
||||
(cook cook-primary-key ;~(pfix ;~(plug whitespace (jester 'primary') whitespace (jester 'key')) ;~(pose ;~(plug clustering ordered-column-list) ordered-column-list)))
|
||||
:: foreign keys
|
||||
@ -436,6 +463,7 @@
|
||||
=/ parse-command ;~ pose
|
||||
(cold %alter-index ;~(plug whitespace (jester 'alter') whitespace (jester 'index')))
|
||||
(cold %alter-namespace ;~(plug whitespace (jester 'alter') whitespace (jester 'namespace')))
|
||||
(cold %alter-table ;~(plug whitespace (jester 'alter') whitespace (jester 'table')))
|
||||
(cold %create-database ;~(plug whitespace (jester 'create') whitespace (jester 'database')))
|
||||
(cold %create-namespace ;~(plug whitespace (jester 'create') whitespace (jester 'namespace')))
|
||||
(cold %create-table ;~(plug whitespace (jester 'create') whitespace (jester 'table')))
|
||||
@ -470,6 +498,20 @@
|
||||
=/ parsed (wonk index-nail)
|
||||
=/ next-cursor
|
||||
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:index-nail])
|
||||
?: ?=([[@ @ @ @ @] [@ @ @ @ @] @] [parsed]) ::"alter index action"
|
||||
%= $
|
||||
script q.q.u.+3.q:index-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed ~ +>.parsed) commands]
|
||||
==
|
||||
?: ?=([[@ @ @ @ @] [@ @ @ @ @] [[@ @ @] %~]] [parsed]) ::"alter index single column"
|
||||
%= $
|
||||
script q.q.u.+3.q:index-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed +>.parsed %rebuild) commands]
|
||||
==
|
||||
?: ?=([[@ @ @ @ @] [@ @ @ @ @] * @] [parsed]) ::"alter index columns action"
|
||||
%= $
|
||||
script q.q.u.+3.q:index-nail
|
||||
@ -477,24 +519,13 @@
|
||||
commands
|
||||
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed +>-.parsed +>+.parsed) commands]
|
||||
==
|
||||
::
|
||||
:: mysterious bug, if only 1 column in list and no action it fails
|
||||
?: ?=([[@ @ @ @ @] [@ @ @ @ @] *] [parsed]) ::"alter index columns"
|
||||
?: ?=([[@ @ @ @ @] [@ @ @ @ @] *] [parsed]) ::"alter index multiple columns"
|
||||
%= $
|
||||
script q.q.u.+3.q:index-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed +>.parsed %rebuild) commands]
|
||||
==
|
||||
::
|
||||
:: also bug, tried changing ast def to (unit (list ordered-column)) and other hacks...wtf
|
||||
?: ?=([[@ @ @ @ @] [@ @ @ @ @] @] [parsed]) ::"alter index action"
|
||||
%= $
|
||||
script q.q.u.+3.q:index-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed ~ +>.parsed) commands]
|
||||
==
|
||||
==
|
||||
!!
|
||||
%alter-namespace
|
||||
~| "Cannot parse namespace {<p.q.command-nail>}"
|
||||
@ -508,6 +539,54 @@
|
||||
commands
|
||||
[`command-ast`(alter-namespace:ast %alter-namespace -<.parsed ->.parsed +<.parsed +>+>+<.parsed +>+>+>.parsed) commands]
|
||||
==
|
||||
%alter-table
|
||||
~| "Cannot parse table {<p.q.command-nail>}"
|
||||
=/ table-nail (parse-alter-table [[1 1] q.q.command-nail])
|
||||
=/ parsed (wonk table-nail)
|
||||
=/ next-cursor
|
||||
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:table-nail])
|
||||
|
||||
~| "parsed: {<parsed>}"
|
||||
~| "remainder: {<q.q.u.+3.q:table-nail>}"
|
||||
|
||||
~| "fks: {<`(build-foreign-keys [-.parsed +>.parsed])>}"
|
||||
|
||||
?: =(+<.parsed %alter-column)
|
||||
%= $
|
||||
script q.q.u.+3.q:table-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-table:ast %alter-table -.parsed +>.parsed ~ ~ ~ ~) commands]
|
||||
==
|
||||
?: =(+<.parsed %add-column)
|
||||
%= $
|
||||
script q.q.u.+3.q:table-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-table:ast %alter-table -.parsed ~ +>.parsed ~ ~ ~) commands]
|
||||
==
|
||||
?: =(+<.parsed %drop-column)
|
||||
%= $
|
||||
script q.q.u.+3.q:table-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ +>.parsed ~ ~) commands]
|
||||
==
|
||||
?: =(+<.parsed %add-fk)
|
||||
%= $
|
||||
script q.q.u.+3.q:table-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ +>.parsed ~) commands]
|
||||
==
|
||||
?: =(+<.parsed %drop-fk)
|
||||
%= $
|
||||
script q.q.u.+3.q:table-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ ~ (build-foreign-keys [-.parsed +>.parsed])) commands]
|
||||
==
|
||||
!!
|
||||
%create-database
|
||||
~| 'Create database must be only statement in script'
|
||||
?> =((lent commands) 0)
|
||||
@ -598,6 +677,8 @@
|
||||
=/ key-name (crip (weld (weld "ix-primary-" (trip +>+<.qualified-table)) (weld "-" (trip +>+>.qualified-table))))
|
||||
=/ primary-key (create-index:ast %create-index key-name qualified-table %.y +<.key +>.key)
|
||||
=/ foreign-keys (build-foreign-keys [qualified-table +>+.parsed])
|
||||
~| "parsed: {<parsed>}"
|
||||
~| "primary-key: {<primary-key>}"
|
||||
%= $
|
||||
script q.q.u.+3.q:table-nail
|
||||
script-position next-cursor
|
||||
|
@ -306,7 +306,7 @@
|
||||
$:
|
||||
%alter-index
|
||||
name=qualified-object
|
||||
object=qualified-object :: because index can be over table or view
|
||||
object=qualified-object
|
||||
columns=(list ordered-column)
|
||||
action=index-action
|
||||
==
|
||||
@ -323,11 +323,11 @@
|
||||
$:
|
||||
%alter-table
|
||||
table=qualified-object
|
||||
alter-columns=(unit (list column))
|
||||
add-columns=(unit (list column))
|
||||
drop-columns=(unit (list @t))
|
||||
add-foreign-keys=(unit (list foreign-key))
|
||||
drop-foreign-keys=(unit (list @t))
|
||||
alter-columns=(list column)
|
||||
add-columns=(list column)
|
||||
drop-columns=(list @t)
|
||||
add-foreign-keys=(list foreign-key)
|
||||
drop-foreign-keys=(list @t)
|
||||
==
|
||||
+$ alter-trigger
|
||||
$:
|
||||
|
@ -31,37 +31,33 @@
|
||||
!> (parse:parse(current-database 'db1') "aLter \0d INdEX\09db.ns.my-index On db.ns.table ( col1 asc , col2\0a desc , col3) \0a dIsable \0a;\0a aLter \0d INdEX\09db..my-index On db..table ( col1 asc ) \0a \0a rEBuild ")
|
||||
::
|
||||
:: alter index 1 column without action is mysteriously broken
|
||||
::++ test-alter-index-1-5
|
||||
:: =/ expected
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') "ALTER INDEX db.ns.my-index ON db.ns.table (col1)")
|
||||
++ test-alter-index-2
|
||||
=/ expected
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER INDEX db.ns.my-index ON db.ns.table (col1)")
|
||||
::
|
||||
:: leading whitespace characters, end delimiter, alter ns.index ns.table columns no action
|
||||
++ test-alter-index-2
|
||||
++ test-alter-index-3
|
||||
=/ expected [%alter-index name=[%qualified-object ship=~ database='db1' namespace='ns' name='my-index'] object=[%qualified-object ship=~ database='db1' namespace='ns' name='table'] columns=~[[%ordered-column column-name='col1' is-ascending=%.y] [%ordered-column column-name='col2' is-ascending=%.n] [%ordered-column column-name='col3' is-ascending=%.y]] action=%rebuild]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') " \0d alter INDEX ns.my-index ON ns.table (col1, col2 desc, col3 asc);")
|
||||
::
|
||||
:: alter index table no columns, action only
|
||||
:: fails on +$ alter-index:ast
|
||||
:: ...
|
||||
:: columns=(list ordered-column)
|
||||
::
|
||||
::++ test-alter-index-3
|
||||
:: =/ expected
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') "ALTER INDEX my-index ON table RESUME")
|
||||
++ test-alter-index-4
|
||||
=/ expected
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER INDEX my-index ON table RESUME")
|
||||
::
|
||||
:: fail when namespace qualifier is not a term
|
||||
++ test-fail-alter-index-3
|
||||
++ test-fail-alter-index-5
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'db2') "alter index my-index ON db.Ns.table (col1, col2) resume")
|
||||
::
|
||||
:: fail when table name is not a term
|
||||
++ test-fail-alter-index-4
|
||||
++ test-fail-alter-index-6
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'other-db') "alter index my-index ON db.ns.Table (col1, col2) resume")
|
||||
::
|
||||
@ -95,6 +91,70 @@
|
||||
::
|
||||
:: alter table
|
||||
::
|
||||
:: tests 1, 2, 3, 5, and extra whitespace characters
|
||||
:: alter column db.ns.table 3 columns ; alter column db..table 1 column
|
||||
++ test-alter-table-1
|
||||
=/ expected1 [%alter-table table=[%qualified-object ship=~ database='db1' namespace='ns' name='table'] alter-columns=~ add-columns=[~ ~[[%column name='col1' column-type='@t'] [%column name='col2' column-type='@p'] [%column name='col3' column-type='@ud']]] drop-columns=~ add-foreign-keys=~ drop-foreign-keys=~]
|
||||
=/ expected2 [%alter-table table=[%qualified-object ship=~ database='db' namespace='dbo' name='table'] alter-columns=~ add-columns=[~ ~[[%column name='col1' column-type='@t']]] drop-columns=~ add-foreign-keys=~ drop-foreign-keys=~]
|
||||
%+ expect-eq
|
||||
!> ~[expected1 expected2]
|
||||
!> (parse:parse(current-database 'db1') " ALtER TaBLE db.ns.table AdD COlUMN ( col1 @t , col2 @p , col3 @ud ) \0a;\0a ALTER TABLE db..table ADD COLUMN (col1 @t) ")
|
||||
::
|
||||
:: alter column table 3 columns
|
||||
++ test-alter-table-2
|
||||
=/ expected [%alter-table table=[%qualified-object ship=~ database='db1' namespace='dbo' name='table'] alter-columns=[~ ~[[%column name='col1' column-type='@t'] [%column name='col2' column-type='@p'] [%column name='col3' column-type='@ud']]] add-columns=~ drop-columns=~ add-foreign-keys=~ drop-foreign-keys=~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER TABLE table ALTER COLUMN (col1 @t, col2 @p, col3 @ud)")
|
||||
::
|
||||
:: alter column table 1 column
|
||||
++ test-alter-table-3
|
||||
=/ expected [%alter-table table=[%qualified-object ship=~ database='db1' namespace='dbo' name='table'] alter-columns=[~ ~[[%column name='col1' column-type='@t']]] add-columns=~ drop-columns=~ add-foreign-keys=~ drop-foreign-keys=~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER TABLE table ALTER COLUMN (col1 @t)")
|
||||
::
|
||||
:: drop column table 3 columns
|
||||
++ test-alter-table-4
|
||||
=/ expected [%alter-table table=[%qualified-object ship=~ database='db1' namespace='dbo' name='table'] alter-columns=~ add-columns=~ drop-columns=[~ ['col1' 'col2' 'col3' ~]] add-foreign-keys=~ drop-foreign-keys=~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER TABLE table DROP COLUMN (col1, col2, col3)")
|
||||
::
|
||||
:: drop column table 1 column
|
||||
++ test-alter-table-5
|
||||
=/ expected [%alter-table table=[%qualified-object ship=~ database='db1' namespace='dbo' name='table'] alter-columns=~ add-columns=~ drop-columns=[~ ['col1' ~]] add-foreign-keys=~ drop-foreign-keys=~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "ALTER TABLE table DROP COLUMN (col1)")
|
||||
::
|
||||
:: add foreign key 1 fk
|
||||
++ test-alter-table-
|
||||
=/ expected
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "")
|
||||
::
|
||||
::
|
||||
++ test-alter-table-
|
||||
=/ expected
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "")
|
||||
::
|
||||
::
|
||||
++ test-alter-table-
|
||||
=/ expected
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "")
|
||||
::
|
||||
::
|
||||
++ test-alter-table-
|
||||
=/ expected
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') "")
|
||||
|
||||
::
|
||||
:: create database
|
||||
|
Loading…
Reference in New Issue
Block a user