migrations: add unique(path_id, module_id) on units

The NOT NULL constraint on units.path is dropped.

A NOT NULL constraint is set on units.path_id.

A UNIQUE constraint is added to (path_id, module_id).

Change-Id: Iab0186b17f905c1f9be014e05307cb426d1b0933
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/282115
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/migrations/000054_add_units_id_module_id_unique.down.sql b/migrations/000054_add_units_id_module_id_unique.down.sql
new file mode 100644
index 0000000..3ccc36d
--- /dev/null
+++ b/migrations/000054_add_units_id_module_id_unique.down.sql
@@ -0,0 +1,11 @@
+-- Copyright 2021 The Go Authors. All rights reserved.
+-- Use of this source code is governed by a BSD-style
+-- license that can be found in the LICENSE file.
+
+BEGIN;
+
+ALTER TABLE units DROP CONSTRAINT units_path_id_module_id_key;
+ALTER TABLE units ALTER COLUMN path_id DROP NOT NULL;
+ALTER TABLE units ALTER COLUMN path ADD NOT NULL;
+
+END;
diff --git a/migrations/000054_add_units_id_module_id_unique.up.sql b/migrations/000054_add_units_id_module_id_unique.up.sql
new file mode 100644
index 0000000..4c879c1
--- /dev/null
+++ b/migrations/000054_add_units_id_module_id_unique.up.sql
@@ -0,0 +1,11 @@
+-- Copyright 2021 The Go Authors. All rights reserved.
+-- Use of this source code is governed by a BSD-style
+-- license that can be found in the LICENSE file.
+
+BEGIN;
+
+ALTER TABLE units ALTER COLUMN path_id SET NOT NULL;
+ALTER TABLE units ADD CONSTRAINT units_path_id_module_id_key UNIQUE(path_id, module_id);
+ALTER TABLE units ALTER COLUMN path DROP NOT NULL;
+
+END;