migrations: add documentation bigint

The rate of growth for the documentation table suggests that the id
column might hit the INTEGER limit as the size of our database grows. We
change this to a BIGINT column now, since its easier to make this change
before this table is used in prod.

The update_documentation_id is changed to update both documentation.id
and documentation.id_bigint with the same value on INSERT or UPDATE.

Change-Id: Id310ed548c2fa3769fbd2707cea4f69295434f2f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/302671
Trust: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Julie Qiu 2021-03-17 15:19:41 -04:00
Родитель 4ccb176072
Коммит c861539528
2 изменённых файлов: 36 добавлений и 0 удалений

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

@ -0,0 +1,17 @@
-- 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 DROP COLUMN id_bigint;
CREATE OR REPLACE FUNCTION update_documentation_id() RETURNS TRIGGER AS $BODY$
BEGIN
NEW.id=nextval('sequence_documentation_id');
RETURN NEW;
END
$BODY$ LANGUAGE PLPGSQL;
ALTER SEQUENCE sequence_documentation_id OWNED BY documentation.id;
END;

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

@ -0,0 +1,19 @@
-- 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 ADD COLUMN id_bigint bigint;
CREATE OR REPLACE FUNCTION update_documentation_id() RETURNS TRIGGER AS $BODY$
BEGIN
NEW.id=nextval('sequence_documentation_id');
-- Update id_bigint with the same value on insert/update.
NEW.id_bigint=NEW.id;
RETURN NEW;
END
$BODY$ LANGUAGE PLPGSQL;
ALTER SEQUENCE sequence_documentation_id OWNED BY documentation.id;
END;