【发布时间】:2019-12-05 14:48:58
【问题描述】:
为元数据创建模板模式以便其他包含数据的模式可以继承它是否安全?
优势:多租户场景的迁移将是无缝的。
缺点:?
例子:
hello=# CREATE SCHEMA template;
hello=# CREATE TABLE template.cities (
name text,
population real,
altitude int;
hello=# CREATE SCHEMA us;
hello=# CREATE TABLE us.cities () INHERITS (template.cities);
hello=# \d us.cities;
Table "us.cities"
Column | Type | Collation | Nullable | Default
------------+--------------+-----------+----------+---------
name | text | | |
population | real | | |
altitude | integer | | |
Inherits: template.cities
hello=# CREATE SCHEMA eu;
hello=# CREATE TABLE eu.cities () INHERITS (template.cities);
hello=# \d eu.cities;
Table "eu.cities"
Column | Type | Collation | Nullable | Default
------------+--------------+-----------+----------+---------
name | text | | |
population | real | | |
altitude | integer | | |
Inherits: template.cities
hello=# ALTER TABLE cities ADD COLUMN state varchar(30);
hello=# \d us.cities;
Table "us.cities"
Column | Type | Collation | Nullable | Default
------------+-----------------------+-----------+----------+---------
name | text | | |
population | real | | |
altitude | integer | | |
state | character varying(30) | | |
Inherits: template.cities
【问题讨论】:
标签: postgresql inheritance database-migration multi-tenant