When writing migrations, define schemas deliberately and avoid redundant or speculative elements. Specifically:
character varying/text where a reasonable limit is known (e.g., use varchar(255) not null instead of bare character varying).added_by uuid not null to track who granted/created a relationship (e.g., linking an API key to a router)._versions table (config_id, version, config jsonb, created_at) so you can track history and prevent stale/overwritten state, e.g.:CREATE TABLE gateway_configs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
organization_id UUID NOT NULL,
gateway_key_id BIGINT,
name VARCHAR(255)
);
CREATE TABLE gateway_config_versions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
config_id UUID NOT NULL REFERENCES gateway_configs(id),
version VARCHAR(255) NOT NULL,
config JSONB NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
);
Applying these rules keeps migrations lean, self-documenting, and free of unnecessary maintenance burden while still supporting correctness and future auditability.