Skip to content

katmore/database-schema-versioning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 

Repository files navigation

The goal of this project is to facilitate easy programmatic changes to a database (known as "database revisions" or "database migrations"). This project currently includes a specification and utilities to perform migrations. Further documentation and tools will be released in the future.

Utilities

The following utilities implement the db-schema-spec specification

Database Schema Versioning Specification

The Database Schema Versioning Specification (or "db-schema-spec" for short) describes the structure of a single conceptual database and its successive revisions.

Latest Major Release

  • db-schema-spec : 1.2 - Major release v1.2

Major Release History

  • db-schema-spec : 1.2 - Major release v1.2
  • db-schema-spec : 1.1 - Initial release
  • db-schema-spec : 1.0 - Development/pre-release

Terminology

The key words "must", "must not", "required", "shall", "shall not", "should", "should not", "recommended", "may", and "optional" in this document are to be interpreted as described in RFC 2119.

Additionally, the key words outlined in the following section shall be interpreted as described.

  • database schema : A single conceptual database with a continuous successive history.
  • schema name : A "name" assigned to a particular database schema; it should be reasonably brief and descriptive.
  • schema version : A numeric "version" which identifies a particular state of a database. It must be an unsigned numeric value; either a whole number (integer) or a decimal (float). This numeric constraint makes it trivial to keep sorting/succession consistent across different programming environments.

Resources

This section provides details regarding the directory structure and JSON object files used to describe a database schema and its schema versions.


schema root

The schema root must be a directory that contains all resources needed to describe a single database schema. It should be a directory specific to the schema and should be the same name as the schema. It must contain a schema.json file.

Consider the example project named my-project as seen in the section below. It has the following directory structure: the top-level contains a directory named db-schema that holds all database schemas, which, in turn, contains directories for the specifications of the schemas having the names something and another something. Therefore, the path my-project/db-schema/something is the schema root for the database schema something; likewise, the path my-project/db-schema/something is the schema root for the database schema another-something.

Example my-project contents...

my-project/ ->
   bin/ ->
      ...
   db-schema/ ->
      something/ ->
         schema.json
         2019/ ->
            19.081501/ ->
               BLL-revisions.sql
               DAL-revisions.sql
               version.json
         2020/ ->
            20.043001/ ->
               revisions.sql
               version.json
      another-something/ ->
         schema.json
         1.0/ ->
            revisions.sql
            version.json
         1.1/ ->
            revisions.sql
            version.json
   src/ ->
      ...

schema.json

The schema.json file contains a single JSON object that describes a database schema. It must be located in the top-level of the schema root which it describes. The JSON object must contain all the properties as described in the following bullet-point list.

schema.json example #1...

{
   "db-schema-spec": "1.2",
   "name" : "something",
   "system" : "mysql",
   "current-version" : "20.043001",
   "version-history" : {
      "20.043001" : "2020/043001",
      "19.081501" : "2019/081501",
      "..."
   }
}

schema.json example #2...

{
   "db-schema-spec": "1.2",
   "name" : "another-something",
   "system" : "mysql",
   "current-version" : "1.1",
   "version-history" : {
      "1.1" : "1.1",
      "1.0" : "1.0",
      "..."
   }
}

version.json

The version.json file contains a single JSON object that describes a schema-version. It must be contained in the top level of the version root it describes.

The JSON object in version.json must contain ALL of the following properties as described:

  • db-schema-spec : The Database Schema Versioning specification release being used in this JSON object.
  • schema : The name of database schema. It should be cross-checked to match the name property of the referring schema.json file.
  • version : A string with the value of the schema version that is being described. It should be cross-checked to match with the referring property in the version-history object of the schema.json file.
  • source : An array of strings; each value is a path (relative to the version root) to a source file that must be successfully executed. Each source file must be executed in the order it occurs in the array.

version.json example #1...

{
   "db-schema-spec": "1.2",
   "schema" : "something",
   "system" : "mysql",
   "version" : "200430.01",
   "command" : [
      "revisions.sql"
   ]
}

version.json example #2...

{
   "db-schema-spec": "1.2",
   "schema" : "another-something",
   "system" : "mysql",
   "version" : "1.0",
   "command" : [
      "DAL-revisions.sql",
      "BLL-revisions.sql"
   ]
}

Legal

This software is distributed under the terms of the MIT license or the GPLv3 license.

Copyright (c) 2015-2020, Doug Bird. All rights reserved.

About

Database Schema Versioning Specification and Utilities

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages