我正在 golang 上写一个宠物项目在线商店。我将单体架构拆分为微服务架构,并为每个微服务使用单独的 postgres 数据库。我有两个微服务:产品微服务和类别微服务 它们的表如下所示:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
create table if not exists products
(
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
description TEXT NOT NULL,
price NUMERIC NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now(),
updated_at TIMESTAMP
);
类别表:
create table categories
(
id serial primary key,
name text not null,
slug text not null,
created_at timestamp not null default now(),
updated_at timestamp
);
如果产品表位于不同的数据库中,如何将类别字段添加到产品表中?是否有这种可能性,或者这些表必须位于同一个数据库中?
我不确定,但我想在升级到数据库级别之前,我会尝试按模式分离功能区域。
如果表之间存在关系,则意味着它们是同一数据库的一部分。