Skip to content

Lazy DDL converter from Cloud Spanner to MySQL for document.

Notifications You must be signed in to change notification settings

nktks/go-ddls2m

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-ddls2m

Lazy DDL converter from Cloud Spanner to MySQL for document. This is not for production use, just for document.(ie ER diagram input)

how to run

with golang runtime

go run cmd/ddls2m/main.go -f spanner_ddl.sql

or you can get binary from https://github.com/nakatamixi/go-ddls2m/releases

convert details

example

cat spanner_ddl.sql
CREATE TABLE `users` (
	`user_id` STRING(36) NOT NULL,
	`name` STRING(MAX) NOT NULL,
	`uid` STRING(255) NOT NULL,
	`created_at` TIMESTAMP NOT NULL,
	`updated_at` TIMESTAMP NOT NULL
) PRIMARY KEY  (`user_id`);
CREATE UNIQUE INDEX idx_users_uid ON users (uid);
CREATE TABLE `friends` (
	`friend_id` INT64 NOT NULL,
	`user_id` STRING(36) NOT NULL,
	`to_id` STRING(36) NOT NULL,
	`created_at` TIMESTAMP NOT NULL,
	`updated_at` TIMESTAMP NOT NULL
) PRIMARY KEY  (`user_id`, `friend_id`),
INTERLEAVE IN PARENT `users` ;
CREATE UNIQUE INDEX idx_friends_user_id_to_id ON friends (user_id, to_id);
CREATE  INDEX idx_friends_to_id ON friends (to_id);
go run cmd/ddls2m/main.go -s spanner_ddl.sql
CREATE TABLE `users` (
	`user_id` VARCHAR(36) NOT NULL,
	`name` TEXT NOT NULL,
	`uid` VARCHAR(255) NOT NULL,
	`created_at` DATETIME NOT NULL,
	`updated_at` DATETIME NOT NULL,
	PRIMARY KEY  (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE UNIQUE INDEX idx_users_uid ON users(uid);
CREATE TABLE `friends` (
	`friend_id` BIGINT NOT NULL,
	`user_id` VARCHAR(36) NOT NULL,
	`to_id` VARCHAR(36) NOT NULL,
	`created_at` DATETIME NOT NULL,
	`updated_at` DATETIME NOT NULL,
	PRIMARY KEY  (`user_id`, `friend_id`),
	FOREIGN KEY  (`user_id`) REFERENCES users (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE UNIQUE INDEX idx_friends_user_id_to_id ON friends(user_id, to_id);
CREATE INDEX idx_friends_to_id ON friends(to_id);

About

Lazy DDL converter from Cloud Spanner to MySQL for document.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published