SQL: Add ON DELETE clause to foreign keys
This makes it easier to remove a complete package or system when debugging.
This commit is contained in:
parent
488b88c3cf
commit
d2d48920f4
2 changed files with 6 additions and 3 deletions
|
|
@ -13,7 +13,7 @@ CREATE TABLE contents (
|
|||
|
||||
CREATE TABLE packages (
|
||||
id SERIAL PRIMARY KEY,
|
||||
system integer NOT NULL REFERENCES systems(id),
|
||||
system integer NOT NULL REFERENCES systems(id) ON DELETE CASCADE,
|
||||
category varchar,
|
||||
name varchar NOT NULL,
|
||||
UNIQUE(system, name, category) -- Note the order, lookups on (system,name) are common
|
||||
|
|
@ -21,14 +21,14 @@ CREATE TABLE packages (
|
|||
|
||||
CREATE TABLE package_versions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
package integer NOT NULL REFERENCES packages(id),
|
||||
package integer NOT NULL REFERENCES packages(id) ON DELETE CASCADE,
|
||||
version varchar NOT NULL,
|
||||
released date NOT NULL,
|
||||
UNIQUE(package, version)
|
||||
);
|
||||
|
||||
CREATE TABLE man (
|
||||
package integer NOT NULL REFERENCES package_versions(id),
|
||||
package integer NOT NULL REFERENCES package_versions(id) ON DELETE CASCADE,
|
||||
name varchar NOT NULL,
|
||||
section varchar NOT NULL,
|
||||
filename varchar NOT NULL,
|
||||
|
|
|
|||
3
sql/update-2016-10-06.sql
Normal file
3
sql/update-2016-10-06.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE packages DROP CONSTRAINT packages_system_fkey, ADD CONSTRAINT packages_system_fkey FOREIGN KEY(system) REFERENCES systems(id) ON DELETE CASCADE;
|
||||
ALTER TABLE package_versions DROP CONSTRAINT package_versions_package_fkey, ADD CONSTRAINT package_versions_package_fkey FOREIGN KEY(package) REFERENCES packages(id) ON DELETE CASCADE;
|
||||
ALTER TABLE man DROP CONSTRAINT man_package_fkey, ADD CONSTRAINT man_package_fkey FOREIGN KEY(package) REFERENCES package_versions(id) ON DELETE CASCADE;
|
||||
Loading…
Add table
Add a link
Reference in a new issue