CodeScene Database Configuration Guide

Overview

CodeScene supports both an embedded database and external database engines for persisting system and analysis configurations. This guide provides detailed instructions on configuring these databases, ensuring secure connections, and performing regular backups to maintain data integrity.

Supported Databases

Embedded Database (H2)

  • Default Option: CodeScene comes with a built-in embedded database (H2) that persists all the data in a single file. This is the recommended choice for most users as it typically does not become a performance bottleneck.

  • Backup: Regular backups are crucial. CodeScene automatically creates a backup file on each startup, stored in the db-backups folder. This can be disabled or configured using environment variables such as CODESCENE_DB_BACKUP_ON_STARTUP and CODESCENE_DB_BACKUP_MAX_PER_DAY.

External Databases

MySQL and MariaDB

  • Supported Versions:

    • MySQL: Minimum version 5.7.x or 8.0.x

    • MariaDB: Minimum version 10.4.6

  • Configuration:

    • Add to your MySQL or MariaDB server configuration:

      [mysqld]
      lower_case_table_names = 1
      sql_generate_invisible_primary_key = 0 # only for MySQL >= 8.0.30
    • Create User and Database:

      Sql
       
      CREATE USER 'sa'@'localhost' IDENTIFIED BY '';
      CREATE DATABASE codescene CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
      GRANT ALL PRIVILEGES ON codescene.* TO 'sa'@'localhost';
  • Migration: Existing CodeScene data can be migrated from H2 to MySQL.

  • Secure Connections: Ensure your database server supports TLS 1.1 or later. Configuration details can be found in the respective secure deployment guides for MySQL 5.7, MySQL 8.0, and MariaDB.

Database Configuration

CodeScene uses the following environment variables to connect to the database:

  • CODESCENE_DB_ENGINE: "h2" (default), "mysql", or "mariadb"

  • CODESCENE_DB_HOST: Default is "localhost"

  • CODESCENE_DB_PORT: Used only for MySQL and MariaDB, default is 3306

  • CODESCENE_DB_NAME: Default is "codescene"

  • CODESCENE_DB_USER: Default is "sa"

  • CODESCENE_DB_PASSWORD: Default is ""

  • CODESCENE_DB_SSL_MODE: SSL mode for MySQL and MariaDB

  • CODESCENE_DB_ENABLED_TLS_PROTOCOLS: Default is "TLSv1,TLSv1.1,TLSv1.2,TLSv1.3"

Backup Strategies

  • Embedded Database (H2): Automatic backups are created on startup. Configure the number of backups and retention period using environment variables.

  • External Databases: Follow specific instructions for MySQL Backup and MariaDB Backup. Consider using managed solutions like Azure Backup for cloud deployments.

Performance Considerations

  • The default H2 database is efficient for most use cases. However, if using an external database like MySQL, ensure low network latency by hosting the database in the same datacenter as CodeScene. For managed services, deploy them in the same region to optimize performance.