Skip to content

Apply naming conventions to constraints and indexes

João Pereira requested to merge db-naming-conventions into database

Problem

Although there are no specific conventions that we should follow at GitLab for naming database indexes and constraints, we should adopt one to improve consistency and discoverability.

Solution

Use the following naming convention:

Type Syntax Example
PRIMARY KEY constraints pk_<table name> pk_repositories
FOREIGN KEY constraints fk_<table name>_<column name>_<referred table name> fk_repository_manifests_manifest_id_manifests
UNIQUE constraints uq_<table name>_<column(s) name> uq_manifest_layers_manifest_id_layer_id
CHECK constraints ck_<table name>_<column(s) name>_<validation name> ck_layers_media_type_length
Indexes ix_<table name>_<column(s) name> ix_tags_manifest_id

This was inspired in https://alembic.sqlalchemy.org/en/latest/naming.html.

Related to &2313 (closed).

Edited by João Pereira

Merge request reports