migrations: add new documentation table and change some PKs

TABLE new_documentation is created, which will replace the documentation
table after reprocessing. new_documentation has the following schema changes:

- id is a BIGINT instead of INTEGER
- goos and goarch are ENUMs
- zip column is dropped, since it is not being used

documentation_symbols is updated with a FK to new_documentation. The
id column is dropped, and id_bigint is renamed to id.

The id column on package_symbols is also dropped and id_bigint is
renamed to id.

Change-Id: I916ed7edd38647cd75f95f05f1fc7ea5b5c8980d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/303113
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Julie Qiu 2021-03-18 18:52:01 -04:00
Родитель d1f5b90c73
Коммит c5b023c085
2 изменённых файлов: 61 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,21 @@
-- 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 documentation_symbols DROP CONSTRAINT IF EXISTS documentation_symbols_documentation_id_fkey;
ALTER TABLE documentation_symbols DROP CONSTRAINT IF EXISTS documentation_symbols_pkey;
ALTER TABLE documentation_symbols RENAME COLUMN id TO id_bigint;
ALTER TABLE documentation_symbols ALTER COLUMN id_bigint DROP IDENTITY IF EXISTS;
ALTER TABLE documentation_symbols ADD COLUMN id INTEGER PRIMARY KEY;
ALTER TABLE package_symbols DROP CONSTRAINT IF EXISTS package_symbols_pkey CASCADE;
ALTER TABLE package_symbols RENAME COLUMN id TO id_bigint;
ALTER TABLE package_symbols ALTER COLUMN id_bigint DROP IDENTITY IF EXISTS;
ALTER TABLE package_symbols ADD COLUMN id INTEGER PRIMARY KEY;
DROP TABLE new_documentation;
END;

Просмотреть файл

@ -0,0 +1,40 @@
-- 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;
CREATE TABLE new_documentation (
id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
unit_id INTEGER NOT NULL,
goos goos NOT NULL,
goarch goarch NOT NULL,
synopsis text NOT NULL,
source bytea,
UNIQUE (unit_id, goos, goarch),
FOREIGN KEY (unit_id) REFERENCES units(id) ON DELETE CASCADE
);
COMMENT ON TABLE new_documentation
IS 'TABLE documentation contains documentation for packages in the database.';
COMMENT ON COLUMN new_documentation.source
IS 'COLUMN source contains the encoded ast.Files for the package.';
ALTER TABLE documentation_symbols DROP COLUMN id;
ALTER TABLE documentation_symbols RENAME COLUMN id_bigint TO id;
ALTER TABLE documentation_symbols ADD PRIMARY KEY (id);
ALTER TABLE documentation_symbols ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY;
ALTER TABLE documentation_symbols
ADD CONSTRAINT documentation_symbols_documentation_id_fkey
FOREIGN KEY (documentation_id)
REFERENCES new_documentation(id) ON DELETE CASCADE;
ALTER TABLE package_symbols DROP COLUMN id CASCADE;
ALTER TABLE package_symbols RENAME COLUMN id_bigint TO id;
ALTER TABLE package_symbols ADD PRIMARY KEY (id);
ALTER TABLE package_symbols ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY;
ALTER TABLE documentation_symbols
ADD CONSTRAINT documentation_symbols_package_id_fkey
FOREIGN KEY (package_symbol_id)
REFERENCES package_symbols(id) ON DELETE CASCADE;
END;