зеркало из https://github.com/golang/pkgsite.git
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:
Родитель
4ccb176072
Коммит
c861539528
|
@ -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;
|
Загрузка…
Ссылка в новой задаче