DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Database Development With Containers, Git, and Migration Scripts

Database Development With Containers, Git, and Migration Scripts

This article discusses the use of containers with Git and migration scripts.

Paul Stanton user avatar by
Paul Stanton
·
May. 16, 19 · Tutorial
Like (1)
Save
Tweet
Share
11.96K Views

Join the DZone community and get the full member experience.

Join For Free

I'm often asked, “What is the best practice for backing up developers' SQL Server containers?”

While containers support backups, a better process treats SQL containers and database clones as code with a source controlled workflow. Full disclosure, I am a principal at Windocks, where we focus on SQL Server containers. This article discusses the use of containers with Git and migration scripts. The same processes, however, will work for anyone working with databases with conventional VMs or instances with Git and migration scripts.

SQL Server Development as Code

SQL Server containers are combined with secure production database clones, Git or other source control system, through a series of steps.

A database clone is built with a SQL container and data masking and other scripts, and integrated with a Git repo (Step 1). Developers self-provision containers with a cloned database, with optional ports and SQL sa password assignment (Steps 2 and 3), with scripts committed to the source repo (Step 4). Developers stay in synch with new commits by provisioning new containers, which each including a clone of the repo. When the scripts are ready for Test, the dev branch is merged to trigger the build of the CI pipeline (Steps 5 and 6).

SQL DevOps with Production Database Clones, Containers, and Git

Containers With Git Cloning and Script Marshalling

Images are built with dockerfiles that define the SQL Server container (mssql-2016), and database clones, scripts, and integration with a Git repo. The example below includes a full backup of the customer's database and a cleanse data script.

At container run time, a Git clone copies the repo into a scripts folder. A Powershell script (combinescripts.ps1) is updated and committed to the repo to concatenate and order migration scripts into a combined “all.sql” script.

Combinescripts.ps1

Get-Content scripts\script1.sql, scripts\script2.sql | Set-Content all.sql

The Git clone and Powershell scripts are included in the dockerfile and applied at run time:

FROM mssql-2017
SETUPCLONING FULL customers C:\windocks\dbbackups\customerdatafull.bak
COPY cleanseData.sql .
RUN cleanseData.sql
ENV USE_DOCKERFILE_TO_CREATE_CONTAINER=1
RUN "C:\Program Files\Git\cmd\git.exe" clone https://github.com/WinDocks/git-db-scripts-runtime.git scripts
RUN powershell.exe scripts\combinescripts.ps1

Developer Self-Service

Developers provision containers using the Windocks web UI, which includes a drop-down list of databases in each image to enable selection of a subset of databases. Each container is named, and a container port and SQL sa password can also be assigned. The image build tool is shown below.

Management Server

Working With a Git Repo

Each new container includes a clone of the Git repo in the scripts folder and the ordered script all.sql. Developers can use standard client tools (SSMS, etc.) to clone the repo to their local workstation and apply the scripts, or they can use selected scripts at run time using the following docker command syntax.

>docker create -e RUN=”scripts/upgrade1.sql, scripts/upgrade2.sql” <imagename>

Conclusions

Developers can use these steps to protect work-in-process without backups and share their work.

Combining SQL Server containers with database clones and Git provides advantages over current practices of “building” databases from source control. Building databases from source requires time and does not identify performance or data-related issues in development. Secure production database clones provide a higher quality artifact for development and test and deliver higher quality software releases. This process also supports complex images that can scale to deliver multi-terabyte environments with scores of databases.

Docker (software) Database Git

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Distributed Tracing: A Full Guide
  • Top 11 Git Commands That Every Developer Should Know
  • Test Execution Tutorial: A Comprehensive Guide With Examples and Best Practices
  • GraphQL Frameworks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: