Giter Club home page Giter Club logo

migrator's Introduction

๐Ÿ‘‹ Hi, Iโ€™m ลukasz Budnik

I know the ล in first name looks terrifying to pronounce. However, it's really simple to pronounce, just say: woo-cash.

๐Ÿ‘€ Iโ€™m interested in distributed systems

I specialise in distributed systems and cloud computing. I've been working with cloud computing (IaaS, PaaS, and SaaS) for almost 10 years!

๐ŸŒฑ Iโ€™m currently learning Kubernetes and Go

๐Ÿค Let's collaborate

Iโ€™m looking to collaborate on the following projects:

๐Ÿ“ซ You can reach me at [email protected]

migrator's People

Contributors

akwiatek avatar dependabot[bot] avatar github-actions[bot] avatar lukaszbudnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

migrator's Issues

implement loader for Azure Blob

implement loader interface for Azure Blob

The Azure Blob implementation should use similar concept to AWS default chain credentials provider so that there are no other additional cloud-vendor specific configuration needed.

rework xcli to core module

A little bit more fancier name of xcli would be core.

Also, xcli is used by server module. So core is a better name for it.

Label DB connections so they can be monitored

@lukaszbudnik One suggestion to make the application easier to use.

In order to make it easier to monitor how Migrator connects with a DB server would be good set application_name upon connecting to the server. This would allow a user to monitor on the DB's side when Migrator is working on.
That feature can come helpful when there is a problem with applying a migration.

Steps to reproduce

I'm testing Migrator against a PostgreSQL server.

  1. Start a migration.
  2. List open DB connections.
SELECT
  application_name,
  query
FROM pg_catalog.pg_stat_activity
WHERE state IS NOT NULL;
    application_name    |                                                                       query                                                                       
  ------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------
   PostgreSQL JDBC Driver | SET application_name = 'PostgreSQL JDBC Driver'
   PostgreSQL JDBC Driver | SET application_name = 'PostgreSQL JDBC Driver'
                          | select name, source_dir as sd, filename, type, db_schema, created, contents, checksum from migrator.migrator_migrations order by name, source_dir
                          | create schema if not exists migrator
  1. The listing shows JDBC connections and lib/pq connections.

Actual results

There is no application_name set for Migrator therefore it is hard to list activity of Migrator only.
On the other hand JDBC connections are labelled and it is easier to track them.

Expected

For a connection with Migrator application_name is set.

SET application_name = 'Migrator'

References

Documentation: https://www.postgresql.org/docs/9.5/runtime-config-logging.html#GUC-APPLICATION-NAME
Proposed function to change:

migrator/db/db.go

Lines 69 to 70 in 6272159

// init initialises migrator by making sure proper schema/table are created
func (bc *baseConnector) init() {

Wrong createVersion summary

I've applied DB migrations and the operation ended successfully.
The migration was suspended for some time due to a secondary transaction.
After the successful migration I got the following summary.

      "summary": {                                                                                                                                                                                
        "startedAt": "2021-09-15T11:08:00.162242499Z",                                                                                                                                            
        "duration": -1948086662,                                                                                                                                                                  
        "tenants": 6,                                                                                                                                                                             
        "singleMigrations": 0,                                                                                                                                                                    
        "tenantMigrationsTotal": 0,                                                                                                                                                               
        "migrationsGrandTotal": 0,                                                                                                                                                                
        "singleScripts": 8,                                                                                                                                                                       
        "tenantScriptsTotal": 246,                                                                                                                                                                
        "scriptsGrandTotal": 254                                                                                                                                                                  
      }                                                                                                                                                                                           

where the duration is obviously wrong - it's negative.

I was wondering why exactly we cast to int32 in the following passage:

results.Duration = int32(time.Since(results.StartedAt.Time))

I presume that time.Since() gave the right calculation but it got broken further down the line.

MS SQL Server support on travis

Currently MS SQL Server is not provided out of the box on Travis. However, Travis supports running docker containers. We could port test/docker/scripts/mssql-create-and-setup-container.sh

CreateVersion and CreateTenant should not fetch version

Currently both CreateVersion and CreateTenant call GetVersionByID to return version with DB migrations.

This could be reworked by simply returning the created Version and DB Migrations directly. The bit missing is that after inserting the DB migration we need to fetch ID of that migration and add to version. There is already mechanism in place in migrator for fetching Version ID so we can replicate it there too.

apply migrations and add tenant to return list of migrations

Currently "response" can be:

  • summary - only summary of executed migrations and scripts
  • full - contains full results including summary with a list of all applied migrations and scripts, the later includes migration/script contents which proved to be too verbose for large systems

The idea is to provide a third, backward compatible, response type:

  • list - this will return same response as in full but without the actual migration/script contents

Loader.GetSourceMigrations() could take SourceMigrationFilters parameter

Coordinator.GetSourceMigrations(*SourceMigrationFilters) operation accepts optional filters inSourceMigrationFilters struct.

Under the hood it is implemented as getting all source migrations from and then filtering them:

func (c *coordinator) GetSourceMigrations(filters *SourceMigrationFilters) []types.Migration {
	allSourceMigrations := c.loader.GetSourceMigrations()
	filteredMigrations := c.filterMigrations(allSourceMigrations, filters)
	return filteredMigrations
}

The implementation could be improved and the specific loader (disk, AWS S3, Azure Blob Storage) could accept*SourceMigrationFilters and return already filtered results - better performance and faster operation.

single and tenant scripts are failing on checksum validation

migrator should allow reloads of single and tenant scripts as these are special types of migrations which are expected to change over a time.

currently if you update single or tenant script migrator will error and return a list of offending migrations.

Move all printing related logic to utils module

At the moment printing tables and String() methods are defined in types module. These should be placed in separate utils module. Also String() method formatting output as table row is too much and looks odd when used in for example tests.

Implement support fo MSSQL

There are some technical challenges for implementing MSSQL (and they are all mentioned in https://github.com/lukaszbudnik/migrator/projects/2).

MSSQL has different syntax for:

  • create table if not exists
  • different way of handling timestamp/date/times

Currently MySQL and PostgreSQL vary only in prepared statement parameter syntax. For MSSQL there much bigger challenges.

Extract table create SQL to dialects

Knowing that other DB engines have different syntax for creating dialects (migrator uses syntax which works for both MySQL and PostgreSQL) migrator should allow overriding default create table syntax.

Implement it in dialects.

rework docker scripts

There should be one script for creating and destroying containers. Name of DB could be passed as argument to create/destroy scripts.

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.