Giter Club home page Giter Club logo

localize-mssql's Introduction

localize-mssql

This repo contains a docker-based solution to containerize and run Microsoft SQL with automated creation of schemas and tables, and population of data from CSV files. This helps with creating a predefined copy of an application's database, which can help with local development, end-to-end testing, etc. This is not a tool per se, but rather a template or a solution using existing tools like docker.

Quick Start ๐Ÿš€

  1. Install Docker Engine
  2. Fork or clone this repo
  3. Duplicate and rename .env.example file to .env and set all values.
  4. Create and populate data folder.
    • Create data/__ddl__ folder and add all DDL statements as .sql files
    • Read the section below to understand how to populate this folder.
  5. (Optional): Rename name inside docker-compose.yml to your project/app name. Default is localize-mssql.
  6. Install all dependencies by running npm install
  7. To create a fresh copy of all tables and data, run npm start. This will initialize the MSSQL server and run all SQL scripts and insert statements.
  8. Once the tables have been populated with the test data, commit the changes to create a new image docker commit <container-id> <app-name>:<tag>.

The created image (which runs MSSQL server with preconfigured test data) can now be used across your dev and testing environments! And this solution works easily with CI too!

Commands

Command Description
docker compose --profile init up -d Initialize MS SQL server, create all tables and schemas,
populate tables with data. (This will also keep the server running)
docker compose stop Stop the server
docker compose start Start the MS SQL server (if initiialization was already done)
docker commit <container-id> <app-name>:<tag> Commit the sql server to create an image with the populated data

Populating the data folder

  • Add all DDL statements inside data/__ddl__/. Prefix with a number for ordering.
    • Example: 01-fileA.sql will be executed before 02-fileB.sql
  • For populating data, create a subdirectory with the schema name, and a csv file with table name.
    • Example: For a table dbo.table1, create a subdirectory dbo (inside the data folder) and a file 01-table1.csv.
    • The numbering before table name ensures the order in which to execute the files. This helps with foreign key constraints.

Issues โš ๏ธ

MSSQL image incompatibility with ARM devices

MSSQL image from Microsoft does not support ARM64 architecture (Apple Silicon devices will be affected). Follow this blog for a workaround. The workaround is to use Rosetta (included in Docker engine) for emulating amd64 images.

References ๐Ÿ“ƒ

localize-mssql's People

Contributors

sgeorge-nb avatar sanjay-george avatar

Watchers

 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.