Code Monkey home page Code Monkey logo

sqlcicd's Introduction

CI/CD for SQL Databases

This repo is meant to demonstrate a process that can help simplify CI/CD for SQL Databases.

What this process gets you:

  • Allows you to write SQL as plain SQL, as opposed to relying on other syntax some tools might force.
  • Allows you to store SQL as plain SQL files with your repo(s), as opposed to having to store them in a tool.
  • Allows use of database differential tools so long as they can output plain SQL file(s).
  • Encourages a convention that helps you think about SQL database changes.
  • Gives you a single command to run to update your database.
  • Per instance tracking of database state, so working with mutliple environments is straightforward.
  • Doesn't couple you too a single tool; the tool here simply automates execution and tracks state, running manually does not require magic.

This process uses a tool called Roundhouse. This tool does two things:

  • Automates execution of your SQL scripts
  • Tracks which scripts it has already ran for your database

The tooling requires that you organize and write your SQL scripts in a certian manner based on when they can be executed. Conceptually, there are three categories:

  • One Time Scripts - Scripts that you only want to run once per database instance, such as DDL or DML.
  • Anytime Scripts - Scripts that can be run at anytime, such as scripts that create/alter functions, indexes, views and stored procedures.
  • Everytime Scripts - Scripts that can & should be run everytime, such as permissions.

By organizing your SQL this way Roundhouse can automate updating your database.

  • It knows that it should only run 'One Time' scripts once, so it tracks if it ran them yet for each instance and if not it runs them.
  • It knows that it can run 'Anytime' scripts whenever, so it runs them if they have changed since it's last run.
  • It knows that it should run 'Everytime' scripts everytime, so it just runs them.

The folder structure

As mentioned, Roundhouse requires organizing your SQL into specific groups, usually I place these folders in a SQL folder inside my project's repo.

One Time Scripts

  • Folder Name: up
  • Naming Convention: Whatever you want so long as they get sorted in desired run order.
    • Eg: 0001-Initial.sql, 0002-NextChange.sql

Anytime Scripts

  • Folder names: functions, indexes, sprocs, views
  • Naming convention: Whatever you want.

Everytime Scripts

  • Folder name: permissions
  • Naming convention: Whatever you want.

For full folder list and conventions see the Roundhouse documentation.


Running Roundhouse

rh.exe /s={databaseServer} /d={databaseName} /vf={versionFile} /f={SqlFolder}

sqlcicd's People

Contributors

andrew-j-hagner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.