Created
March 3, 2016 01:08
-
-
Save mix3/b5cc90a552776d8501c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requires "SQL::Translator::Producer::PlantUML"; | |
requires "DBD::mysql"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE user ( | |
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, | |
name VARCHAR(191) NOT NULL, | |
PRIMARY KEY (id) | |
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4; | |
CREATE TABLE item ( | |
id INTEGER UNSIGNED NOT NULL, | |
name VARCHAR(191) NOT NULL, | |
PRIMARY KEY (id) | |
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4; | |
CREATE TABLE user_item ( | |
user_id INTEGER UNSIGNED NOT NULL, | |
item_id INTEGER UNSIGNED NOT NULL, | |
amount INTEGER UNSIGNED NOT NULL, | |
PRIMARY KEY (user_id, item_id), | |
FOREIGN KEY (user_id) REFERENCES user (id), | |
FOREIGN KEY (item_id) REFERENCES item (id) | |
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4; | |
CREATE TABLE user_item_history ( | |
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, | |
user_id INTEGER UNSIGNED NOT NULL, | |
item_id INTEGER UNSIGNED NOT NULL, | |
how_get INTEGER UNSIGNED NOT NULL, | |
how_out INTEGER UNSIGNED NOT NULL, | |
amount INTEGER UNSIGNED NOT NULL, | |
created_at DATETIME NOT NULL, | |
PRIMARY KEY (id), | |
FOREIGN KEY (user_id, item_id) REFERENCES user_item (user_id, item_id) | |
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use DBI; | |
use SQL::Translator; | |
my $dbh = DBI->connect("dbi:mysql:dbname=example", "root", "", { | |
AutoCommit => 1, | |
PrintError => 0, | |
RaiseError => 1, | |
ShowErrorStatement => 1, | |
AutoInactiveDestroy => 1, | |
mysql_enable_utf8 => 1, | |
mysql_auto_reconnect => 0, | |
}); | |
my $got = SQL::Translator->new( | |
parser => 'DBI', | |
parser_args => { dbh => $dbh }, | |
to => 'PlantUML', | |
)->translate; | |
$got =~ s/^\s*\n//mg; | |
print $got; | |
exit; |
Author
mix3
commented
Mar 3, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment