Idempotent schema management for MySQL, PostgreSQL, and more

Overview

sqldef sqldef

The easiest idempotent MySQL/PostgreSQL/SQLite3/SQL Server schema management by SQL.

This is inspired by Ridgepole but using SQL, so there's no need to remember Ruby DSL.

demo

Installation

Download the single-binary executable for your favorite database from:

https://github.com/k0kubun/sqldef/releases

Usage

mysqldef

mysqldef should work in the same way as mysql for setting connection information.

$ mysqldef --help
Usage:
  mysqldef [options] db_name

Application Options:
  -u, --user=user_name              MySQL user name (default: root)
  -p, --password=password           MySQL user password, overridden by $MYSQL_PWD
  -h, --host=host_name              Host to connect to the MySQL server (default: 127.0.0.1)
  -P, --port=port_num               Port used for the connection (default: 3306)
  -S, --socket=socket               The socket file to use for connection
      --password-prompt             Force MySQL user password prompt
      --enable-cleartext-plugin     Enable/disable the clear text authentication plugin
      --file=sql_file               Read schema SQL from the file, rather than stdin (default: -)
      --dry-run                     Don't run DDLs but just show them
      --export                      Just dump the current schema to stdout
      --skip-drop                   Skip destructive changes such as DROP
      --help                        Show this help
      --version                     Show this version

Example

# Make sure that MySQL server can be connected by mysql(1)
$ mysql -uroot test -e "select 1;"
+---+
| 1 |
+---+
| 1 |
+---+

# Dump current schema by adding `def` suffix and --export
$ mysqldef -uroot test --export
CREATE TABLE `user` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(191) DEFAULT 'k0kubun',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

# Save it to edit
$ mysqldef -uroot test --export > schema.sql

Update the schema.sql like (instead of ADD INDEX, you can just add KEY index_name (name) in the CREATE TABLE as well):

 CREATE TABLE user (
   id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
   name VARCHAR(128) DEFAULT 'k0kubun',
+  created_at DATETIME NOT NULL
 ) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
+
+ALTER TABLE user ADD INDEX index_name(name);

And then run:

# Check the auto-generated migration plan without execution
$ mysqldef -uroot test --dry-run < schema.sql
--- dry run ---
Run: 'ALTER TABLE user ADD COLUMN created_at datetime NOT NULL ;'
Run: 'ALTER TABLE user ADD INDEX index_name(name);'

# Run the above DDLs
$ mysqldef -uroot test < schema.sql
Run: 'ALTER TABLE user ADD COLUMN created_at datetime NOT NULL ;'
Run: 'ALTER TABLE user ADD INDEX index_name(name);'

# Operation is idempotent, safe for running it multiple times
$ mysqldef -uroot test < schema.sql
Nothing is modified

# Run without droping existing tables and columns
$ mysqldef -uroot test --skip-drop < schema.sql
Skipped: 'DROP TABLE users;'

psqldef

psqldef should work in the same way as psql for setting connection information.

$ psqldef --help
Usage:
  psqldef [option...] db_name

Application Options:
  -U, --user=username        PostgreSQL user name (default: postgres)
  -W, --password=password    PostgreSQL user password, overridden by $PGPASSWORD
  -h, --host=hostname        Host or socket directory to connect to the PostgreSQL server (default: 127.0.0.1)
  -p, --port=port            Port used for the connection (default: 5432)
      --password-prompt      Force PostgreSQL user password prompt
  -f, --file=filename        Read schema SQL from the file, rather than stdin (default: -)
      --dry-run              Don't run DDLs but just show them
      --export               Just dump the current schema to stdout
      --skip-drop            Skip destructive changes such as DROP
      --help                 Show this help

You can use PGSSLMODE environment variable to specify sslmode.

Example

# Make sure that PostgreSQL server can be connected by psql(1)
$ psql -U postgres test -c "select 1;"
 ?column?
----------
        1
(1 row)

# Dump current schema by adding `def` suffix and --export
$ psqldef -U postgres test --export
CREATE TABLE public.users (
    id bigint NOT NULL,
    name text,
    age integer
);

CREATE TABLE public.bigdata (
    data bigint
);

# Save it to edit
$ psqldef -U postgres test --export > schema.sql

Update the schema.sql like:

 CREATE TABLE users (
     id bigint NOT NULL PRIMARY KEY,
-    name text,
     age int
 );

-CREATE TABLE bigdata (
-    data bigint
-);

And then run:

# Check the auto-generated migration plan without execution
$ psqldef -U postgres test --dry-run < schema.sql
--- dry run ---
Run: 'DROP TABLE bigdata;'
Run: 'ALTER TABLE users DROP COLUMN name;'

# Run the above DDLs
$ psqldef -U postgres test < schema.sql
Run: 'DROP TABLE bigdata;'
Run: 'ALTER TABLE users DROP COLUMN name;'

# Operation is idempotent, safe for running it multiple times
$ psqldef -U postgres test < schema.sql
Nothing is modified

# Run without droping existing tables and columns
$ psqldef -U postgres test --skip-drop < schema.sql
Skipped: 'DROP TABLE users;'

sqlite3def

$ sqlite3def --help
Usage:
  sqlite3def [option...] db_name

Application Options:
  -f, --file=filename    Read schema SQL from the file, rather than stdin (default: -)
      --dry-run          Don't run DDLs but just show them
      --export           Just dump the current schema to stdout
      --skip-drop        Skip destructive changes such as DROP
      --help             Show this help

mssqldef

Usage:
  mssqldef [options] db_name

Application Options:
  -U, --user=user_name       MSSQL user name (default: sa)
  -P, --password=password    MSSQL user password, overridden by $MSSQL_PWD
  -h, --host=host_name       Host to connect to the MSSQL server (default: 127.0.0.1)
  -p, --port=port_num        Port used for the connection (default: 1433)
      --password-prompt      Force MSSQL user password prompt
      --file=sql_file        Read schema SQL from the file, rather than stdin (default: -)
      --dry-run              Don't run DDLs but just show them
      --export               Just dump the current schema to stdout
      --skip-drop            Skip destructive changes such as DROP
      --help                 Show this help
      --version              Show this version

Supported features

Following DDLs can be generated by updating CREATE TABLE. Some of them can also be used for input schema file.

  • MySQL
    • Table: CREATE TABLE, DROP TABLE
    • Column: ADD COLUMN, CHANGE COLUMN, DROP COLUMN
    • Index: ADD INDEX, ADD UNIQUE INDEX, CREATE INDEX, CREATE UNIQUE INDEX, DROP INDEX
    • Primary key: ADD PRIMARY KEY, DROP PRIMARY KEY
    • Foreign Key: ADD FOREIGN KEY, DROP FOREIGN KEY
    • View: CREATE VIEW, CREATE OR REPLACE VIEW, DROP VIEW
  • PostgreSQL
    • Table: CREATE TABLE, DROP TABLE
    • Column: ADD COLUMN, ALTER COLUMN, DROP COLUMN
    • Index: CREATE INDEX, CREATE UNIQUE INDEX, DROP INDEX
    • Foreign / Primary Key: ADD FOREIGN KEY, DROP CONSTRAINT
    • Policy: CREATE POLICY, DROP POLICY
    • View: CREATE VIEW, CREATE OR REPLACE VIEW, DROP VIEW
  • SQLite3
    • Table: CREATE TABLE, DROP TABLE
    • View: CREATE VIEW, DROP VIEW
  • SQL Server
    • Table: CREATE TABLE, DROP TABLE
    • Column: ADD COLUMN, DROP COLUMN, DROP CONSTRAINT
    • Index: ADD INDEX, DROP INDEX
    • Primary key: ADD PRIMARY KEY, DROP PRIMARY KEY
    • VIEW: CREATE VIEW, DROP VIEW

MySQL examples

CREATE TABLE

+CREATE TABLE users (
+  name VARCHAR(40) DEFAULT NULL
+);

Remove the statement to DROP TABLE.

ADD COLUMN

 CREATE TABLE users (
   name VARCHAR(40) DEFAULT NULL,
+  created_at DATETIME NOT NULL
 );

Remove the line to DROP COLUMN.

CHANGE COLUMN

 CREATE TABLE users (
-  name VARCHAR(40) DEFAULT NULL,
+  name CHAR(40) DEFAULT NULL,
   created_at DATETIME NOT NULL
 );

ADD INDEX

 CREATE TABLE users (
   name CHAR(40) DEFAULT NULL,
   created_at DATETIME NOT NULL,
+  UNIQUE KEY index_name(name)
 );

or

 CREATE TABLE users (
   name CHAR(40) DEFAULT NULL,
   created_at DATETIME NOT NULL
 );
+
+ALTER TABLE users ADD UNIQUE INDEX index_name(name);

Remove the line to DROP INDEX.

ADD PRIMARY KEY

 CREATE TABLE users (
+  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
   name CHAR(40) DEFAULT NULL,
   created_at datetime NOT NULL,
   UNIQUE KEY index_name(name)
 );

Remove the line to DROP PRIMARY KEY.

Composite primary key may not work for now.

ADD FOREIGN KEY

 CREATE TABLE users (
   id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
   name CHAR(40) DEFAULT NULL,
   created_at datetime NOT NULL,
   UNIQUE KEY index_name(name)
 );

 CREATE TABLE posts (
   user_id BIGINT UNSIGNED NOT NULL,
+  CONSTRAINT posts_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id)
 );

Remove the line to DROP FOREIGN KEY.

Composite foreign key may not work for now.

CREATE (OR REPLACE) VIEW

 CREATE VIEW foo AS
   select u.id as id, p.id as post_id
   from  (
     mysqldef_test.users as u
     join mysqldef_test.posts as p on ((u.id = p.user_id))
   )
 ;
+ CREATE OR REPLACE VIEW foo AS select u.id as id, p.id as post_id from (mysqldef_test.users as u join mysqldef_test.posts as p on (((u.id = p.user_id) and (p.is_deleted = 0))));

Remove the line to DROP VIEW.

PostgreSQL examples

CREATE TABLE

+CREATE TABLE users (
+  id BIGINT PRIMARY KEY
+);

Remove the statement to DROP TABLE.

ADD COLUMN

 CREATE TABLE users (
   id BIGINT PRIMARY KEY,
+  name VARCHAR(40)
 );

Remove the line to DROP COLUMN.

CREATE INDEX

 CREATE TABLE users (
   id BIGINT PRIMARY KEY,
   name VARCHAR(40)
 );
+CREATE INDEX index_name on users (name);

Remove the line to DROP INDEX.

ADD FOREIGN KEY

 CREATE TABLE users (
   id BIGINT PRIMARY KEY,
   name VARCHAR(40)
 );
 CREATE INDEX index_name on users (name);

 CREATE TABLE posts (
   user_id BIGINT,
+  CONSTRAINT fk_posts_user_id FOREIGN KEY (user_id) REFERENCES users (id)
 )

Remove the line to DROP CONSTRAINT.

ADD POLICY

 CREATE TABLE users (
   id BIGINT PRIMARY KEY,
   name VARCHAR(40)
 );
 CREATE POLICY p_users ON users AS PERMISSIVE FOR ALL TO PUBLIC USING (id = (current_user)::integer) WITH CHECK ((name)::text = current_user)

+CREATE POLICY p_users ON users AS PERMISSIVE FOR ALL TO PUBLIC USING (id = (current_user)::integer) WITH CHECK ((name)::text = current_user)

Remove the line to DROP POLICY.

CREATE (OR REPLACE) VIEW

 CREATE VIEW foo AS
   select u.id as id, p.id as post_id
   from  (
     mysqldef_test.users as u
     join mysqldef_test.posts as p on ((u.id = p.user_id))
   )
 ;
+ CREATE OR REPLACE VIEW foo AS select u.id as id, p.id as post_id from (users as u join posts as p on (((u.id = p.user_id) and (p.is_deleted = 0))));

Remove the line to DROP VIEW.

Distributions

Linux

A debian package might be supported in the future, but for now it has not been implemented yet.

# mysqldef
wget -O - https://github.com/k0kubun/sqldef/releases/latest/download/mysqldef_linux_amd64.tar.gz \
  | tar xvz

# psqldef
wget -O - https://github.com/k0kubun/sqldef/releases/latest/download/psqldef_linux_amd64.tar.gz \
  | tar xvz

macOS

Homebrew tap is available.

# mysqldef
brew install sqldef/sqldef/mysqldef

# psqldef
brew install sqldef/sqldef/psqldef

Limitations

Because sqldef distinguishes table/index/column by its name, sqldef does NOT support:

  • RENAME TABLE
  • RENAME INDEX
    • DROP + ADD could be fine for index, though
  • CHANGE COLUMN for rename

To rename them, you would need to rename manually and use --export again.

Development

You can use the following command to prepare command line tools and DB servers for running tests.

# Linux
$ sudo apt install mysql-client postgresql-client
$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
$ sudo apt-get update && sudo apt-get install mssql-tools # then add: export PATH="$PATH:/opt/mssql-tools/bin"

# macOS
$ brew install libpq && brew link --force libpq
$ brew install microsoft/mssql-release/mssql-tools

$ docker-compose up
$ make test

License

Unless otherwise noted, the sqldef source files are distributed under the MIT License found in the LICENSE file.

sqlparser is distributed under the Apache Version 2.0 license found in the sqlparser/LICENSE.md file.

Issues
  • Cannot add nullable TIMESTAMP column

    Cannot add nullable TIMESTAMP column

    Problem

    With adding a new nullable TIMESTAMP column in schema, mysqldef will generate a DDL without specifying NULL or not and result in an error like following

    ERROR 1067 (42000): Invalid default value for 'created_at'
    
    Environment
    • mysqldef: 0.5.14
    • mysql: 5.7

    Test Case

    Initial Schema
    CREATE TABLE user (
      id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
      name VARCHAR(128) DEFAULT 'konsumer'
    ) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
    
    New Schema
    CREATE TABLE user (
      id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
      name VARCHAR(128) DEFAULT 'konsumer',
      created_at TIMESTAMP NULL DEFAULT NULL
    ) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
    

    Current Generated DDLs

    ALTER TABLE user ADD COLUMN created_at timestamp DEFAULT null AFTER name
    

    Expected Generated DDLs

    ALTER TABLE user ADD COLUMN created_at timestamp NULL DEFAULT null AFTER name
    

    I tried to run the expected one locally and it works fine on MySQL.

    opened by CYBAI 20
  • Wasm

    Wasm

    Related to #45

    This includes basic wasm build to wrap just the DDL stuff for the web. You can use it to make a live demo of what the CLI does, or just use it as a web-based tool for diffing SQL.

    I tried getting proper error-handling working, and get it running better in node, but haven't worked it out, so I will probly just leave this as it is, and switch my node-lib to wrap the go CLI.

    I think there are lots of benefits to compiling to wasm, like running in many environments, faster runtimes, etc, but I think maybe go-wasm isn't quite there, or at least I can't work it out, yet.

    Thats said, this is still useful as a web-based demo.

    opened by konsumer 13
  • mssqldef: support declare in trigger

    mssqldef: support declare in trigger

    I made a change to allow DECLARE ... to be used in the trigger syntax.

    We can declare variables and cursors within the declare syntax. Cursor can be used when we want to loop through the result set one record at a time.

    This change only supports declarations, so it is just a test to check the parsing, but I can change it to meaningful tests with cursors by supporting Fetch cursor ... and OPEN cursor ... after this.

    opened by ytakaya 12
  • wasm support

    wasm support

    Hi, I am new to go, and use nodejs mostly.

    I am interested in compiling this awesome project as a wasm library, so It can be used on the web & in node (I am thinking it would be an awesome alternative to knex migrations.) wasm is cross-platform, so I imagine it would be a great way to distribute it for javascript targets (rather than node-only compiled library / exec calls to CLI.) It also opens up the possibility of using it in lots of other languages.

    In my naivety, I just changed GOOS=js and GOARCH=wasm in Makefile, but I get this error when I run make:

    # github.com/howeyc/gopass
    ../../../../howeyc/gopass/terminal.go:24:9: undefined: terminal.State
    make: *** [Makefile:14: build] Error 2
    

    I am thinking this particular problem is the password-prompt for CLI usage.

    I really just want to use the diffing & parsing as a lib, as node already has nice password prompt, for example, and has good native postgres client, but also web can't make the requests directly (but it might be cool to have a client side webform that does "here is the SQL to do a diff".)

    As a total go-newb, I think it may be a bit beyond me. Would anyone who is good with go want to wrap the lib for wasm-compilation? I'll keep hammering at it, but if you have any suggestions, they'd be much appreciated.

    Is this something you want a PR for? I I could also make a node project that exposes it and publishes to npm. I will try to make a wasm/sqldef entry-point and add it to makefile, but again, I'm not the strongest with go, so it might take a while and not be up to snuff :)

    opened by konsumer 11
  • Adding support for a new database

    Adding support for a new database

    Hi Takashi,

    Thank you for this awesome project. I was interested to know how difficult is it to add support for a completely new database. I was looking for clickhouse (https://github.com/ClickHouse/ClickHouse) support. I would like to know what all components need to be updated for adding a new database support.

    opened by chhetripradeep 10
  • sqlite3def Windows AMD64 binary is a stub, not working

    sqlite3def Windows AMD64 binary is a stub, not working

    --export output

    2021/09/06 11:46:33 Error on DumpDDLs: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub

    Input SQL

    (any)

    Current output

    Under Windows, using sqlite3def_windows_amd64 :

    > .\sqlite3def.exe /f sqlite3.sql test.db
    2021/09/06 11:43:09 Error on DumpDDLs: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
    

    Expected output

    > .\sqlite3def.exe /f sqlite3.sql test.db
    (Something like applying statements, without error)
    
    opened by shunf4 9
  • Failed to parse of DDL containing CURRENT_TIMESTAMP(6)

    Failed to parse of DDL containing CURRENT_TIMESTAMP(6)

    My environment:

    • MySQL Server version: 5.7.25 Homebrew
    • mysqldef : v0.5.15

    Case containing CURRENT_TIMESTAMP(6)

    Failed to parse of DDL.

    $ mysql -u root -e 'create database my_db'
    $ cat schema.sql
    CREATE TABLE `users` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
      `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
    $ ./mysqldef  --file=schema.sql my_db
    found syntax error when parsing DDL "CREATE TABLE `users` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
      `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC": syntax error at position 135
    

    I made sure that schema.sql has the correct syntax.

    $ mysql -u root my_db < schema.sql
    $ mysql -u root my_db -e 'show create table users;'
    +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Table | Create Table                                                                                                                                                                                                                                                                                                                                   |
    +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | users | CREATE TABLE `users` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
      `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC |
    +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    

    Case not containing CURRENT_TIMESTAMP(6)

    The DDL is successfully applied.

    $ mysql -u root -e 'create database my_db2'
    $ cat schema.sql
    CREATE TABLE `users` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `created_at` datetime(6) NOT NULL,
      `updated_at` datetime(6) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
    $ ./mysqldef  --file=schema.sql my_db2
    -- Apply --
    CREATE TABLE `users` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `created_at` datetime(6) NOT NULL,
      `updated_at` datetime(6) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
    
    opened by tokubass 8
  • Feature request: support altering charset and collation

    Feature request: support altering charset and collation

    This is a feature request to support altering charset and collation although it is already stated at https://github.com/k0kubun/sqldef/issues/47 as

    Parse column's collate (and maybe charset as well) and support altering them.

    Also, it looks charset and collation are not reflected on adding a new column. At least, I am happy if charset and collation on adding a new column is supported.

    opened by sonots 8
  • psqldef can't add unique constraint.

    psqldef can't add unique constraint.

    Description

    I want to create unique constraint to use upsert statement in postgresql. However, add constraint statement fails with an error on psqldef.

    --export output

    -- No table exists --
    

    Input SQL

    create table dummy(
        column_a int not null 
        ,column_b int not null 
        ,column_c int not null
    );
    
    alter table dummy add constraint dummy_uniq unique (column_a, column_b);
    

    Current output

    found syntax error when parsing DDL "alter table dummy add constraint dummy_uniq unique (column_a, column_b)": syntax error at position 33 near 'constraint'
    

    Expected output

    create table dummy(
        column_a int not null 
        ,column_b int not null 
        ,column_c int not null
    );
    
    alter table dummy add constraint dummy_uniq unique (column_a, column_b);
    
    opened by subaru-shoji 7
  • syntax error when parsing

    syntax error when parsing "MySQL-specific comment"

    Hi! I got a error when running this command

    mysqldef -uroot test --dry-run < new_schema.sql
    
    ...
    ...
    FULLTEXT KEY `job_detail_fulltext_index` (`job_detail`) /*!50100 WITH PARSER `ngram` */ ,
      FULLTEXT KEY `title_fulltext_index` (`title`) /*!50100 WITH PARSER `ngram` */ ,
      CONSTRAINT `jobs_client_id_foreign` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
      CONSTRAINT `jobs_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci": syntax error at position 3824 near 'fulltext'
    

    I think it's the "MySQL-specific comment" breaks the parsing process.

    where in my case, the /*!50100 WITH PARSERngram*/ was generated by mysql automatically when querying the show create table.

      FULLTEXT KEY `title_fulltext_index` (`title`) /*!50100 WITH PARSER `ngram` */ ,
    

    By the way, the export command shown below works fine.

    mysqldef -uroot test --export > new_schema.sql
    

    What do you think…? Thanks!

    opened by yaquawa 7
Releases(v0.11.20)
Owner
Takashi Kokubun
Ruby committer developing JIT compiler. Maintainer of ERB and Haml.
Takashi Kokubun
GitHub's Online Schema Migrations for MySQL

gh-ost GitHub's online schema migration for MySQL gh-ost is a triggerless online schema migration solution for MySQL. It is testable and provides paus

Leon 0 Apr 3, 2020
Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers.

Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers. It is a stand

Adrian Macneil 2.3k Jan 15, 2022
Database schema evolution library for Go

Try browsing the code on Sourcegraph! Darwin Database schema evolution library for Go Example package main import ( "database/sql" "log" "github.

Guiabolso 125 Dec 28, 2021
SQL schema migration tool for Go.

sql-migrate SQL Schema migration tool for Go. Based on gorp and goose. Using modl? Check out modl-migrate. Features Usable as a CLI tool or as a libra

Ruben Vermeersch 2.4k Jan 21, 2022
Simple migration tool for MySQL

prrn Simple migration tool for MySQL This is a CLI that helps you create a DB migration file. There is no need to write up and down files from scratch

kamijin_fanta 7 Nov 10, 2021
Opinionated tool for database structure management and migrations

trek Requirements At least version 13 of postgres is needed. Installation go install . Setup Create config.yaml: model_name: <model_name> db_name: <db

Stack11 3 Jan 7, 2022
Database migrations. CLI and Golang library.

migrate Database migrations written in Go. Use as CLI or import as library. Migrate reads migrations from sources and applies them in correct order to

null 7.9k Jan 23, 2022
Database migrations. CLI and Golang library.

Database migrations written in Go. Use as CLI or import as library.

null 27 May 30, 2021
A simple database migration tool using an sql.DB connection and fs.FS for the migration source

A simple database migration tool using an sql.DB connection and fs.FS for the migration source. It has no non-test dependencies.

 maragu 33 Dec 9, 2021
Schema management CLI for MySQL

Skeema is a tool for managing MySQL tables and schema changes in a declarative fashion using pure SQL. It provides a CLI tool allowing you to: Export

Skeema 973 Jan 11, 2022
Interactive terminal user interface and CLI for database connections. MySQL, PostgreSQL. More to come.

?? dbui dbui is the terminal user interface and CLI for database connections. It provides features like, Connect to multiple data sources and instance

Kanan Rahimov 71 Jan 14, 2022
A tool to compare if terraform provider migration schema snapshot is equal to schema defined in resource code

migration schema comparer for Terraform When develop Terraform provider sometimes we need do some state migration(not schema migration) via StateUpgra

null 0 Nov 18, 2021
Go-mysql-orm - Golang mysql orm,dedicated to easy use of mysql

golang mysql orm 个人学习项目, 一个易于使用的mysql-orm mapping struct to mysql table golang结构

magacy 1 Jan 10, 2022
GitHub's Online Schema Migrations for MySQL

gh-ost GitHub's online schema migration for MySQL gh-ost is a triggerless online schema migration solution for MySQL. It is testable and provides paus

GitHub 9.6k Jan 13, 2022
GitHub's Online Schema Migrations for MySQL

gh-ost GitHub's online schema migration for MySQL gh-ost is a triggerless online schema migration solution for MySQL. It is testable and provides paus

Leon 0 Apr 3, 2020
wrench - Schema management tool for Cloud Spanner -

wrench wrench is a schema management tool for Cloud Spanner. Please feel free to report issues and send pull requests, but note that this application

Cloud Spanner Ecosystem 142 Jan 22, 2022
WAL-G is an archival restoration tool for PostgreSQL, MySQL/MariaDB, and MS SQL Server (beta for MongoDB and Redis).

WAL-G is an archival restoration tool for PostgreSQL, MySQL/MariaDB, and MS SQL Server (beta for MongoDB and Redis).

null 2k Jan 22, 2022
Examples and code to assign a name to your MongoDB, MySQL, PostgreSQL, RabbitMQ, and redis connection.

your connection deserves a name ?? When your app interacts with an external system, assign a name to the connection. An external system in this contex

Andy Grunwald 24 Nov 15, 2021
Simple key-value store abstraction and implementations for Go (Redis, Consul, etcd, bbolt, BadgerDB, LevelDB, Memcached, DynamoDB, S3, PostgreSQL, MongoDB, CockroachDB and many more)

gokv Simple key-value store abstraction and implementations for Go Contents Features Simple interface Implementations Value types Marshal formats Road

Philipp Gillé 390 Jan 16, 2022
Command line tool to generate idiomatic Go code for SQL databases supporting PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server

About xo xo is a command-line tool to generate Go code based on a database schema or a custom query. xo works by using database metadata and SQL intro

XO 3k Jan 20, 2022
100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood.

go-queryset 100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood. Contents

Denis Isaev 646 Jan 11, 2022
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.

upper/db is a productive data access layer (DAL) for Go that provides agnostic tools to work with different data sources

upper.io 2.9k Jan 21, 2022
Interactive client for PostgreSQL and MySQL

dblab Interactive client for PostgreSQL and MySQL. Overview dblab is a fast and lightweight interactive terminal based UI application for PostgreSQL a

Daniel Omar Vergara Pérez 169 Jan 17, 2022
Cross check makes health checks on PostgreSQL and MySQL database servers

Cross Check Cross check makes health checks on PostgreSQL and MySQL database servers, it also performs master & slave control for clusters in H/A Acti

Ali 2 Jan 14, 2022
Quick and dirty test to compare MySQL perf between ARM64 & Rosetta MySQL on M1Pro mac

Quick and dirty test to compare MySQL perf between ARM64 & Rosetta MySQL on M1Pro mac

Chris Atkins 0 Nov 5, 2021
Beerus-DB: a database operation framework, currently only supports Mysql, Use [go-sql-driver/mysql] to do database connection and basic operations

Beerus-DB · Beerus-DB is a database operation framework, currently only supports Mysql, Use [go-sql-driver/mysql] to do database connection and basic

Beerus 2 Dec 26, 2021
Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package

Go-MySQL-Driver A MySQL-Driver for Go's database/sql package Features Requirements Installation Usage DSN (Data Source Name) Password Protocol Address

Go SQL Drivers 11.8k Jan 23, 2022
mysql to mysql 轻量级多线程的库表数据同步

goMysqlSync golang mysql to mysql 轻量级多线程库表级数据同步 测试运行 设置当前binlog位置并且开始运行 go run main.go -position mysql-bin.000001 1 1619431429 查询当前binlog位置,参数n为秒数,查询结

null 12 Dec 8, 2021
Golang mysql orm, a personal learning project, dedicated to easy use of mysql

golang mysql orm 个人学习项目, 一个易于使用的mysql-orm mapping struct to mysql table golang结构

magacy 1 Dec 30, 2021