PostgreSQL

Database Design

The PostgreSQL database is designed to store GitLab’s core data, such as users, projects, repositories, and CI/CD pipelines. It leverages the power of a relational database system to provide a structured and efficient storage mechanism.

Schema: The schema defines the structure of the database, including tables, columns, and relationships between them. The GitLab schema is extensive and well-documented.

Tables:

  • users: Stores information about GitLab users.
  • projects: Stores information about GitLab projects.
  • repositories: Stores information about GitLab repositories.
  • ci_builds: Stores information about CI/CD builds.
  • ci_pipelines: Stores information about CI/CD pipelines.

Relationships:

  • Users can have multiple projects.
  • Projects can have multiple repositories.
  • Repositories can have multiple CI/CD pipelines.

Data Types:

  • integer: Stores whole numbers.
  • text: Stores strings of text.
  • timestamp with time zone: Stores timestamps with time zone information.
  • boolean: Stores true or false values.

Querying

PostgreSQL provides a powerful SQL language for querying the database.

Syntax:

SELECT column1, column2
          FROM table_name
          WHERE condition;
          

Examples:

  • Retrieve all users:
SELECT *
          FROM users;
          
  • Retrieve projects owned by a specific user:
SELECT *
          FROM projects
          WHERE owner_id = 123;
          
  • Retrieve CI/CD pipelines for a specific project:
SELECT *
          FROM ci_pipelines
          WHERE project_id = 456;
          

Migrations

GitLab uses migrations to manage database schema changes over time.

Process:

  1. Create a migration file.
  2. Define the schema changes in the migration file.
  3. Run the migrations to apply the changes to the database.

Example:

class AddNewColumnToUsers < ActiveRecord::Migration[6.1]
            def change
              add_column :users, :new_column, :string
            end
          end
          

References