Skip to content

Commit edbfedd

Browse files
authored
Merge pull request #1041 from rolang/add-completions-role-policy-comment-analyze
Add completions: alter role, create/alter/drop policy, comment, analyze, alter function
2 parents 73f2f36 + 553d3d3 commit edbfedd

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

modules/core/shared/src/main/scala/data/Completion.scala

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ object Completion {
3434
case object AlterType extends Completion
3535
case object CreateFunction extends Completion
3636
case object DropFunction extends Completion
37+
case object AlterFunction extends Completion
3738
case class Copy(count: Int) extends Completion
3839
case object Show extends Completion
3940
case object Do extends Completion
@@ -51,6 +52,7 @@ object Completion {
5152
case object DropDatabase extends Completion
5253
case object CreateRole extends Completion
5354
case object DropRole extends Completion
55+
case object AlterRole extends Completion
5456
case object CreateMaterializedView extends Completion
5557
case object RefreshMaterializedView extends Completion
5658
case object DropMaterializedView extends Completion
@@ -65,6 +67,11 @@ object Completion {
6567
case object Revoke extends Completion
6668
case object AlterIndex extends Completion
6769
case class Merge(count: Int) extends Completion
70+
case object CreatePolicy extends Completion
71+
case object AlterPolicy extends Completion
72+
case object DropPolicy extends Completion
73+
case object Comment extends Completion
74+
case object Analyze extends Completion
6875
// more ...
6976

7077
/**

modules/core/shared/src/main/scala/net/message/CommandComplete.scala

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ object CommandComplete {
6969
case "ALTER TYPE" => apply(Completion.AlterType)
7070
case "CREATE FUNCTION" => apply(Completion.CreateFunction)
7171
case "DROP FUNCTION" => apply(Completion.DropFunction)
72+
case "ALTER FUNCTION" => apply(Completion.AlterFunction)
7273
case "SHOW" => apply(Completion.Show)
7374
case "DO" => apply(Completion.Do)
7475
case "CREATE PROCEDURE" => apply(Completion.CreateProcedure)
@@ -85,6 +86,7 @@ object CommandComplete {
8586
case "DROP DATABASE" => apply(Completion.DropDatabase)
8687
case "CREATE ROLE" => apply(Completion.CreateRole)
8788
case "DROP ROLE" => apply(Completion.DropRole)
89+
case "ALTER ROLE" => apply(Completion.AlterRole)
8890
case "CREATE MATERIALIZED VIEW" => apply(Completion.CreateMaterializedView)
8991
case "REFRESH MATERIALIZED VIEW" => apply(Completion.RefreshMaterializedView)
9092
case "DROP MATERIALIZED VIEW" => apply(Completion.DropMaterializedView)
@@ -104,6 +106,11 @@ object CommandComplete {
104106
case "REVOKE" => apply(Completion.Revoke)
105107
case "ALTER INDEX" => apply(Completion.AlterIndex)
106108
case Patterns.Merge(s) => apply(Completion.Merge(s.toInt))
109+
case "COMMENT" => apply(Completion.Comment)
110+
case "CREATE POLICY" => apply(Completion.CreatePolicy)
111+
case "ALTER POLICY" => apply(Completion.AlterPolicy)
112+
case "DROP POLICY" => apply(Completion.DropPolicy)
113+
case "ANALYZE" => apply(Completion.Analyze)
107114
// more .. fill in as we hit them
108115

109116
case s => apply(Completion.Unknown(s))

modules/tests/shared/src/test/scala/CommandTest.scala

+74-1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ class CommandTest extends SkunkTest {
242242
CREATE ROLE skunk_role
243243
""".command
244244

245+
val alterRole: Command[Void] =
246+
sql"ALTER ROLE skunk_role WITH PASSWORD '123'".command
247+
245248
val dropRole: Command[Void] =
246249
sql"""
247250
DROP ROLE skunk_role
@@ -295,6 +298,11 @@ class CommandTest extends SkunkTest {
295298
END;'
296299
""".command
297300

301+
val alterFunction: Command[Void] =
302+
sql"""
303+
ALTER FUNCTION my_trigger_func() RESET search_path
304+
""".command
305+
298306
val dropFunction: Command[Void] =
299307
sql"DROP FUNCTION my_trigger_func;".command
300308

@@ -331,6 +339,35 @@ class CommandTest extends SkunkTest {
331339
FROM skunk_role
332340
""".command
333341

342+
val addComment : Command[Void] =
343+
sql"COMMENT ON TABLE city IS 'A city'".command
344+
345+
val removeComment : Command[Void] =
346+
sql"COMMENT ON TABLE city IS NULL".command
347+
348+
val createPolicy: Command[Void] =
349+
sql"""
350+
CREATE POLICY my_policy ON city
351+
TO CURRENT_USER
352+
WITH CHECK (FALSE)
353+
""".command
354+
355+
val alterPolicy: Command[Void] =
356+
sql"""
357+
ALTER POLICY my_policy
358+
ON city TO CURRENT_USER
359+
WITH CHECK (TRUE)
360+
""".command
361+
362+
val dropPolicy: Command[Void] =
363+
sql"DROP POLICY my_policy ON city".command
364+
365+
val analyze: Command[Void] =
366+
sql"ANALYZE city".command
367+
368+
val analyzeVerbose: Command[Void] =
369+
sql"ANALYZE VERBOSE city".command
370+
334371
sessionTest("create table, create index, alter table, alter index, drop index and drop table") { s =>
335372
for {
336373
c <- s.execute(createTable)
@@ -359,6 +396,8 @@ class CommandTest extends SkunkTest {
359396
_ <- assert("completion", c == Completion.AlterTrigger)
360397
c <- s.execute(dropTrigger)
361398
_ <- assert("completion", c == Completion.DropTrigger)
399+
c <- s.execute(alterFunction)
400+
_ <- assert("completion", c == Completion.AlterFunction)
362401
c <- s.execute(dropFunction)
363402
_ <- assert("completion", c == Completion.DropFunction)
364403
_ <- s.assertHealthy
@@ -387,6 +426,18 @@ class CommandTest extends SkunkTest {
387426
} yield "ok"
388427
}
389428

429+
sessionTest("create, alter and drop policy") { s =>
430+
for {
431+
c <- s.execute(createPolicy)
432+
_ <- assert("completion", c == Completion.CreatePolicy)
433+
c <- s.execute(alterPolicy)
434+
_ <- assert("completion", c == Completion.AlterPolicy)
435+
c <- s.execute(dropPolicy)
436+
_ <- assert("completion", c == Completion.DropPolicy)
437+
_ <- s.assertHealthy
438+
} yield "ok"
439+
}
440+
390441
sessionTest("create view, drop view"){ s=>
391442
for{
392443
c <- s.execute(createView)
@@ -458,10 +509,12 @@ class CommandTest extends SkunkTest {
458509
} yield "ok"
459510
}
460511

461-
sessionTest("create role, drop role") { s =>
512+
sessionTest("create role, alter role, drop role") { s =>
462513
for {
463514
c <- s.execute(createRole)
464515
_ <- assert("completion", c == Completion.CreateRole)
516+
c <- s.execute(alterRole)
517+
_ <- assert("completion", c == Completion.AlterRole)
465518
c <- s.execute(dropRole)
466519
_ <- assert("completion", c == Completion.DropRole)
467520
} yield "ok"
@@ -484,6 +537,26 @@ class CommandTest extends SkunkTest {
484537
} yield "ok"
485538
}
486539

540+
sessionTest("add comment, remove comment") { s =>
541+
for{
542+
c <- s.execute(addComment)
543+
_ <- assert("completion", c == Completion.Comment)
544+
c <- s.execute(removeComment)
545+
_ <- assert("completion", c == Completion.Comment)
546+
_ <- s.assertHealthy
547+
} yield "ok"
548+
}
549+
550+
sessionTest("analyze") { s =>
551+
for{
552+
c <- s.execute(analyze)
553+
_ <- assert("completion", c == Completion.Analyze)
554+
v <- s.execute(analyzeVerbose)
555+
_ <- assert("completion", v == Completion.Analyze)
556+
_ <- s.assertHealthy
557+
} yield "ok"
558+
}
559+
487560
sessionTest("set constraints") { s =>
488561
s.transaction.use { _ =>
489562
for {

0 commit comments

Comments
 (0)