Skip to content

Commit a809d33

Browse files
Hunternessmnd999renetapopova
authored
Add DROP DATABASE name CASCADE ALIASES (#1805)
to drop any aliases blocking the deletion of the database Documenting neo-technology/neo4j#26465, ~~needs to wait until that has been merged.~~ --------- Co-authored-by: Mark Dixon <[email protected]> Co-authored-by: Reneta Popova <[email protected]>
1 parent ffe6b43 commit a809d33

File tree

4 files changed

+108
-6
lines changed

4 files changed

+108
-6
lines changed

modules/ROOT/pages/database-administration/aliases/manage-aliases-composite-databases.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ SHOW ALIASES FOR DATABASE YIELD *
160160
+-----------------------------------------------------------------------------------------------------------------------------------+
161161
----
162162

163+
[[delete-composite-database-alias]]
163164
== Delete database aliases in composite databases
164165

165166
To delete an alias in a composite database, use the `DROP ALIAS FOR DATABASE` command.

modules/ROOT/pages/database-administration/composite-databases/delete-composite-databases.adoc

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,63 @@
33
[[composite-databases-delete]]
44
= Delete composite databases
55

6-
You can delete composite databases using either the command `DROP COMPOSITE DATABASE name` or the more general one `DROP DATABASE name`.
7-
However, keep in mind that the first command will fail if the target database is not composite, while the second one will not fail because it targets any database.
6+
There are two ways of deleting a composite database with constituent database aliases (local or remote) by either dropping the constituent database aliases first and then deleting the composite database, or deleting the composite database while also dropping the constituent database aliases.
7+
8+
[[composite-databases-delete-without-aliases]]
9+
== Delete a composite database
10+
11+
Before deleting a composite database, you must ensure that it is not in use by any database aliases.
12+
If the composite database is in use, you must first drop the aliases that reference it.
13+
For more information, see xref:database-administration/aliases/manage-aliases-composite-databases.adoc#delete-composite-database-alias[Delete database aliases in composite databases].
14+
15+
You can delete composite databases using either the command `DROP COMPOSITE DATABASE name` or the more general one `DROP DATABASE name`.
16+
However, keep in mind that the first command targets only composite databases, while the second one targets any database.
817

918
.Query
1019
[source, cypher]
1120
----
1221
DROP COMPOSITE DATABASE inventory
1322
----
1423

24+
[role=label--new-5.24]
25+
[[composite-databases-delete-with-aliases]]
26+
== Delete a composite database while dropping its constituents
27+
28+
You can use the `CASCADE ALIASES` option of the `DROP COMPOSITE DATABASE` Cypher command to drop the constituent database aliases while deleting the composite database.
29+
30+
[NOTE]
31+
====
32+
This operation does not deletes the actual target databases of the constituent database aliases.
33+
====
34+
35+
The `CASCADE ALIASES` option is useful when you want to delete a composite database and its constituent database aliases in one step.
36+
Using `CASCADE ALIASES` requires the `DROP ALIAS` privilege.
37+
For more information about this privilege, see xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-alias-management[ALIAS MANAGEMENT privileges].
38+
39+
.Drop a composite database and its consitutent alias
40+
====
41+
This example shows how to create a composite database `movies` and a database alias `movies.sweden` for the database `swedish-movies` and then delete the alias `sweden` and the composite database `movies`.
42+
43+
.Create a composite database `movies` and a database alias `movies.sweden` for the database `swedish-movies`
44+
[source, cypher]
45+
----
46+
CREATE COMPOSITE DATABASE movies
47+
CREATE ALIAS movies.sweden FOR DATABASE `swedish-movies`
48+
----
49+
50+
.Delete the composite database `movies` while also dropping the alias `movies.sweden`
51+
[source, cypher]
52+
----
53+
DROP COMPOSITE DATABASE movies CASCADE ALIASES
54+
----
55+
====
56+
57+
This behavior is the same for the more general command `DROP DATABASE name` when using it to drop a composite database.
58+
59+
//The option `RESTRICT` explicitly requests the default behavior of the command.
60+
61+
[NOTE]
62+
====
63+
For composite databases, the aliases that are dropped when using the `CASCADE ALIASES` option can be found in the `constituents` column of `SHOW DATABASE`.
64+
====
65+

modules/ROOT/pages/database-administration/standard-databases/delete-databases.adoc

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Note that all database aliases must be dropped before dropping a database.
1717
|
1818
[source, syntax, role="noheader"]
1919
----
20-
DROP [COMPOSITE] DATABASE name [IF EXISTS] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT]
20+
DROP [COMPOSITE] DATABASE name [IF EXISTS] [RESTRICT \| CASCADE ALIAS[ES]] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT]
2121
----
2222

2323
|===
@@ -92,9 +92,9 @@ In Neo4j, dumps can be stored in the directory specified by the xref:configurati
9292
The option `DESTROY DATA` explicitly requests the default behavior of the command.
9393

9494
[[delete-existing-db-with-dump]]
95-
=== Delete a database with `IF{nbsp}EXISTS` and `DUMP DATA`/ `DESTROY DATA`
95+
=== Delete a database with `IF{nbsp}EXISTS` and `DUMP DATA`/`DESTROY DATA`
9696

97-
The options `IF EXISTS` and `DUMP DATA`/ `DESTROY DATA` can also be combined.
97+
The options `IF EXISTS` and `DUMP DATA`/`DESTROY DATA` can also be combined.
9898

9999
An example could look like this:
100100

@@ -103,4 +103,54 @@ An example could look like this:
103103
DROP DATABASE customers IF EXISTS DUMP DATA
104104
----
105105

106+
[[delete-databases-with-aliases]]
107+
=== Delete a database with local database aliases targeting it
108+
109+
There are two ways of dropping a database that is the target of local database aliases:
110+
111+
* Drop the local database aliases first, then use `DROP DATABASE name` to drop the database.
112+
Remote database aliases targeting the database do not affect the deletion of the database and therefore dos not need to be dropped beforehand.
113+
* Use `DROP DATABASE name CASCADE ALIASES` to also drop the local database aliases targeting it while dropping the database.
114+
If any of the dropped database aliases are constituents of composite databases, those composite databases will not be dropped.
115+
This command does not affect the remote database aliases targeting the database being dropped.
116+
They will simply no longer resolve their targets as if they were created targeting a non-existing database.
117+
118+
Using `CASCADE ALIASES` requires the `DROP ALIAS` privilege.
119+
For more information about the privilege, see xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-alias-management[ALIAS MANAGEMENT privileges].
120+
121+
.Drop a database and the local database alias targeting it
122+
====
123+
The following example creates a database `movies` and a local database alias `films` targeting it:
124+
125+
[source, cypher]
126+
----
127+
CREATE DATABASE movies
128+
CREATE ALIAS films FOR DATABASE movies
129+
----
130+
131+
Then, the database `movies` and the local database alias `films` can be dropped using the following command:
132+
133+
[source, cypher]
134+
----
135+
DROP DATABASE movies CASCADE ALIASES
136+
----
137+
====
138+
139+
The option `RESTRICT` explicitly requests the default behavior of the command.
140+
141+
[NOTE]
142+
====
143+
For standard databases, the aliases that are dropped when using the `CASCADE ALIASES` option can be found in the `aliases` column of `SHOW DATABASE`.
144+
====
145+
146+
[[delete-existing-databases-with-aliases]]
147+
=== Delete a database with `RESTRICT`/`CASCADE ALIASES` and other command parts
148+
149+
The options `RESTRICT`/`CASCADE ALIASES` can also be combined with `IF EXISTS` and `DUMP DATA`/`DESTROY DATA`.
150+
For example:
151+
152+
[source, cypher]
153+
----
154+
DROP DATABASE movies IF EXISTS CASCADE ALIASES DUMP DATA
155+
----
106156

modules/ROOT/pages/database-administration/syntax.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ START DATABASE name [WAIT [n [SEC[OND[S]]]]\|NOWAIT]
176176
|
177177
[source, syntax, role="noheader"]
178178
----
179-
DROP [COMPOSITE] DATABASE name [IF EXISTS] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT]
179+
DROP [COMPOSITE] DATABASE name [IF EXISTS] [RESTRICT \| CASCADE ALIAS[ES]] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT]
180180
----
181181

182182
|===

0 commit comments

Comments
 (0)