ちょっと話題の記事

DBにダミーデータを作成する「fake2db」を触ってみた

2015.01.21

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、せーのです。今日はプログラマーなら重宝するであろうツールをご紹介致します。名前を「fake2db」といいます。

どんなもの?

こちらは名前のとおり「fake」なデータをDBに入れるツールとなります。本番稼働前の開発時はもちろん、本番稼働後も不具合のチェック等で確認したいが本番データは契約上使えない、というような場合にサッとダミーデータが作れるととても便利ですね。

概要

ではfake2dbの概要です。fake2dbはPython製でpipにてインストール致します。ダミーデータを作れるDBはsqlite, mysql, postgresql, mongodb, redisと大体のメジャーなDBは押さえているような感じです。

やってみる

では早速やってみましょう。mysqlとpostgresqlで試してみます。AWSのRDSを使ってそれぞれのDBを立て、ツールインストール用にEC2を立てます。Amazon LinuxにはデフォルトでPythonが入っているのでpipのみインストールします。

[root@ip-10-0-0-238 ~]# easy_install pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 6.0.6
Downloading https://pypi.python.org/packages/source/p/pip/pip-6.0.6.tar.gz#md5=bbb17814bdf82187f46aaf9cec6b6caa
Processing pip-6.0.6.tar.gz
Writing /tmp/easy_install-cb1kfZ/pip-6.0.6/setup.cfg
Running pip-6.0.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-cb1kfZ/pip-6.0.6/egg-dist-tmp-3jwfKq
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 6.0.6 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2.6 script to /usr/bin
Installing pip2 script to /usr/bin

Installed /usr/lib/python2.6/site-packages/pip-6.0.6-py2.6.egg
Processing dependencies for pip
Finished processing dependencies for pip
[root@ip-10-0-0-238 ~]# which pip
/usr/bin/pip
[root@ip-10-0-0-238 ~]#

次にpipを使ってfake2dbをインストールします。

[root@ip-10-0-0-238 ~]# pip install fake2db
Collecting fake2db
  Downloading fake2db-0.2.1.tar.gz
Collecting fake-factory>=0.4.2 (from fake2db)
  Downloading fake-factory-0.4.2.tar.gz (306kB)
    100% |################################| 307kB 645kB/s
Installing collected packages: fake-factory, fake2db
  Running setup.py install for fake-factory
    changing mode of build/scripts-2.6/faker from 644 to 755
    changing mode of /usr/bin/faker to 755
  Running setup.py install for fake2db
    Installing fake2db script to /usr/bin
Successfully installed fake-factory-0.4.2 fake2db-0.2.1
[root@ip-10-0-0-238 ~]#

そんなこんなをしているうちにRDBがたちあがりました。[test]がmysql, [test-postgres]がpostgresqlです。

fake2db

EC2側から接続テストをしてみます。

[root@ip-10-0-0-238 ~]# yum install mysql postgresql -y
[root@ip-10-0-0-238 ~]# mysql -h test.XXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com -utest -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>quit;
Bye
[root@ip-10-0-0-238 ~]# psql -h test-postgres.XXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com -Utest
ユーザ test のパスワード:
psql (9.2.9, サーバー 9.3.5)
注意: psql バージョン 9.2, サーバーバージョン 9.3.
         psql の機能の中で、動作しないものがあるかもしれません。
SSL 接続 (暗号化方式: DHE-RSA-AES256-SHA, ビット長: 256)
"help" でヘルプを表示します.

test=>\q
[root@ip-10-0-0-238 ~]#

両方つながることを確認しました。ではダミーデータを流してみます。試しにSQLiteから。

[ec2-user@ip-10-0-0-238 ~]$ fake2db --rows 200 --db sqlite
2015-01-21 13:14:46,591 10.0.0.238 ec2-user Rows argument : 200
2015-01-21 13:14:46,610 10.0.0.238 ec2-user Database created and opened succesfully: sqlite_AQMLTLFA.db
2015-01-21 13:14:46,658 10.0.0.238 ec2-user simple_registration Commits are successful after write job!
2015-01-21 13:14:46,738 10.0.0.238 ec2-user detailed_registration Commits are successful after write job!
2015-01-21 13:14:46,827 10.0.0.238 ec2-user companies Commits are successful after write job!
2015-01-21 13:14:46,868 10.0.0.238 ec2-user user_agent Commits are successful after write job!
2015-01-21 13:14:46,967 10.0.0.238 ec2-user customer Commits are successful after write job!
[ec2-user@ip-10-0-0-238 ~]$ ll
合計 216
-rw-r--r-- 1 ec2-user ec2-user 218112  1月 21 13:14 sqlite_AQMLTLFA.db
[ec2-user@ip-10-0-0-238 ~]$

SQLite用のデータが出来上がりました。次にmysqlに流してみましょう。mysqlに流すにはpythonからのコネクタが必要なのでそちらをインストールしてから流します。

[root@ip-10-0-0-238 ~]# pip install mysql-connector-python --allow-external mysql-connector-python
Collecting mysql-connector-python
  Downloading http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.2.zip (274kB)
    100% |################################| 278kB 32.1MB/s
Installing collected packages: mysql-connector-python
  Running setup.py install for mysql-connector-python
Successfully installed mysql-connector-python-2.0.2
[root@ip-10-0-0-238 ~]# exit
logout
[ec2-user@ip-10-0-0-238 ~]$ fake2db --rows 200 --db mysql --name test --host test.XXXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com --password testtest
2015-01-21 13:17:53,465 10.0.0.238 ec2-user Rows argument : 200
2015-01-21 13:17:53,501 10.0.0.238 ec2-user Your mysql server is offline, fake2db will try to launch it now!
/bin/sh: mysqld: コマンドが見つかりません
2015-01-21 13:17:56,525 10.0.0.238 ec2-user Access denied for user 'root'@'10.0.0.238' (using password: YES)
[ec2-user@ip-10-0-0-238 ~]$

エラーを吐きました。どうやらrootでつなぎにいっているようです。しかしhelpを見てみると

[ec2-user@ip-10-0-0-238 ~]$ fake2db --help
usage: fake2db [-h] [--rows ROWS] [--db DB] [--name NAME] [--host HOST]
               [--port PORT] [--password PASSWORD]

optional arguments:
  -h, --help           show this help message and exit
  --rows ROWS          Amount of rows desired per table
  --db DB              Db type for creation: sqlite, mysql, postgresql,
                       mongodb, couchdb, to be expanded
  --name NAME          OPTIONAL : Give a name to the db to be generated.
  --host HOST          OPTIONAL : Hostname of db.
  --port PORT          OPTIONAL : Port of db.
  --password PASSWORD  OPTIONAL : Password for root.

ユーザーを指定するオプションが見当たりません。というかパスワードにも[for root]と思いっきり書いてあります。直接スクリプトの中身を見てみると

/usr/lib/python2.6/site-packages/fake2db/mysql_handler.py

import sys

from helpers import fake2db_logger, str_generator, rnd_id_generator


logger, extra_information = fake2db_logger()

try:
    import mysql.connector
    
......中略......

    def database_caller_creator(self, host, port, password, name=None):
        '''creates a mysql db
        returns the related connection object
        which will be later used to spawn the cursor
        '''
        cursor = None
        conn = None

        try:
            if name:
                db = name
            else:
                db = 'mysql_' + str_generator(self)

            conn = mysql.connector.connect(user='root', host=host, port=port, password=password)
            cursor = conn.cursor()
            cursor.execute('CREATE DATABASE IF NOT EXISTS ' + db)
            cursor.execute('USE ' + db)
            logger.warning('Database created and opened succesfully: %s' % db, extra=extra_information)

        except mysql.connector.Error as err:
            logger.error(err.msg, extra=extra_information)
            sys.exit(1)

        return cursor, conn

......後略......

おお、まさかのベタ書き。ということでこのconn = mysql.connector.connect(user='root'のuserを修正してもう一回流してみます。

[ec2-user@ip-10-0-0-238 ~]$ fake2db --rows 200 --db mysql --name test --host test.XXXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com --password testtest
2015-01-21 13:19:18,429 10.0.0.238 ec2-user Rows argument : 200
2015-01-21 13:19:18,464 10.0.0.238 ec2-user Your mysql server is offline, fake2db will try to launch it now!
/bin/sh: mysqld: コマンドが見つかりません
2015-01-21 13:19:21,480 10.0.0.238 ec2-user Database created and opened succesfully: test
2015-01-21 13:19:21,624 10.0.0.238 ec2-user Table creation ops finished
2015-01-21 13:19:21,674 10.0.0.238 ec2-user simple_registration Commits are successful after write job!
2015-01-21 13:19:21,780 10.0.0.238 ec2-user detailed_registration Commits are successful after write job!
2015-01-21 13:19:21,876 10.0.0.238 ec2-user companies Commits are successful after write job!
2015-01-21 13:19:21,928 10.0.0.238 ec2-user user_agent Commits are successful after write job!
2015-01-21 13:19:22,057 10.0.0.238 ec2-user detailed_registration Commits are successful after write job!

一旦ローカルにつなぎにいったりしていますが、とりあえず入ったっぽいです。確認してみましょう。

[ec2-user@ip-10-0-0-238 ~]$ mysql -h test.XXXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com -utest -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables from test;
+-----------------------+
| Tables_in_test        |
+-----------------------+
| company               |
| customer              |
| detailed_registration |
| simple_registration   |
| user_agent            |
+-----------------------+
5 rows in set (0.00 sec)

mysql> select count(*) from company;
+----------+
| count(*) |
+----------+
|      200 |
+----------+
1 row in set (0.00 sec)

mysql>

確認できました。続いてpostgresqlです。postgresqlと繋ぐには「psycopg2」というモジュールが必要で、こいつを入れるためには「postgresql-devel」と「python-devel」と一般的なビルドツール(gccとか)が必要なので入れておきましょう。

[root@ip-10-0-0-238 ~]# yum install -y python-devel
読み込んだプラグイン:priorities, update-motd, upgrade-helper
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ python-devel.noarch 1:2.6-2.26.amzn1 を インストール
--> 依存性の処理をしています: python-devel-abi = 2.6 のパッケージ: 1:python-devel-2.6-2.26.amzn1.noarch
--> トランザクションの確認を実行しています。
---> パッケージ python26-devel.x86_64 0:2.6.9-1.55.amzn1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

=================================================================================================================================
 Package                          アーキテクチャー         バージョン                          リポジトリー                 容量
=================================================================================================================================
インストール中:
 python-devel                     noarch                   1:2.6-2.26.amzn1                    amzn-main                   4.3 k
依存性関連でのインストールをします:
 python26-devel                   x86_64                   2.6.9-1.55.amzn1                    amzn-main                   177 k

トランザクションの要約
=================================================================================================================================
インストール  1 パッケージ (+1 個の依存関係のパッケージ)

総ダウンロード容量: 181 k
インストール容量: 456 k
Downloading packages:
(1/2): python-devel-2.6-2.26.amzn1.noarch.rpm                                                             | 4.3 kB     00:00
(2/2): python26-devel-2.6.9-1.55.amzn1.x86_64.rpm                                                         | 177 kB     00:00
---------------------------------------------------------------------------------------------------------------------------------
合計                                                                                             1.9 MB/s | 181 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : python26-devel-2.6.9-1.55.amzn1.x86_64                                                           1/2
  インストール中          : 1:python-devel-2.6-2.26.amzn1.noarch                                                             2/2
  検証中                  : python26-devel-2.6.9-1.55.amzn1.x86_64                                                           1/2
  検証中                  : 1:python-devel-2.6-2.26.amzn1.noarch                                                             2/2

インストール:
  python-devel.noarch 1:2.6-2.26.amzn1

依存性関連をインストールしました:
  python26-devel.x86_64 0:2.6.9-1.55.amzn1

完了しました!
[root@ip-10-0-0-238 ~]# pip install psycopg2
Collecting psycopg2
  Using cached psycopg2-2.5.4.tar.gz
Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.4 (dt dec pq3 ext)" -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -DPG_VERSION_HEX=0x090209 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python2.6 -I. -I/usr/include/pgsql92 -I/usr/include/pgsql92/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.6/psycopg/psycopgmodule.o -Wdeclaration-after-statement
    
......中略......
    
    gcc -pthread -shared build/temp.linux-x86_64-2.6/psycopg/psycopgmodule.o build/temp.linux-x86_64-2.6/psycopg/green.o build/temp.linux-x86_64-2.6/psycopg/pqpath.o build/temp.linux-x86_64-2.6/psycopg/utils.o build/temp.linux-x86_64-2.6/psycopg/bytes_format.o build/temp.linux-x86_64-2.6/psycopg/connection_int.o build/temp.linux-x86_64-2.6/psycopg/connection_type.o build/temp.linux-x86_64-2.6/psycopg/cursor_int.o build/temp.linux-x86_64-2.6/psycopg/cursor_type.o build/temp.linux-x86_64-2.6/psycopg/diagnostics_type.o build/temp.linux-x86_64-2.6/psycopg/error_type.o build/temp.linux-x86_64-2.6/psycopg/lobject_int.o build/temp.linux-x86_64-2.6/psycopg/lobject_type.o build/temp.linux-x86_64-2.6/psycopg/notify_type.o build/temp.linux-x86_64-2.6/psycopg/xid_type.o build/temp.linux-x86_64-2.6/psycopg/adapter_asis.o build/temp.linux-x86_64-2.6/psycopg/adapter_binary.o build/temp.linux-x86_64-2.6/psycopg/adapter_datetime.o build/temp.linux-x86_64-2.6/psycopg/adapter_list.o build/temp.linux-x86_64-2.6/psycopg/adapter_pboolean.o build/temp.linux-x86_64-2.6/psycopg/adapter_pdecimal.o build/temp.linux-x86_64-2.6/psycopg/adapter_pint.o build/temp.linux-x86_64-2.6/psycopg/adapter_pfloat.o build/temp.linux-x86_64-2.6/psycopg/adapter_qstring.o build/temp.linux-x86_64-2.6/psycopg/microprotocols.o build/temp.linux-x86_64-2.6/psycopg/microprotocols_proto.o build/temp.linux-x86_64-2.6/psycopg/typecast.o -L/usr/lib64 -L/usr/lib64/pgsql92 -lpython2.6 -lpq -o build/lib.linux-x86_64-2.6/psycopg2/_psycopg.so
Successfully installed psycopg2-2.5.4
[root@ip-10-0-0-238 ~]#

準備ができました。では流してみます。

[ec2-user@ip-10-0-0-238 ~]$ fake2db --rows 200 --db postgresql --name test --host test-postgres.XXXXXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com --password testtest
2015-01-21 13:48:43,955 10.0.0.238 ec2-user Rows argument : 200
2015-01-21 13:48:43,986 10.0.0.238 ec2-user Your postgresql server is offline, fake2db will try to launch it now!
/bin/sh: postgres: コマンドが見つかりません
createdb: データベース template1 に接続できませんでした: サーバに接続できませんでした: そのようなファイルやディレクトリはありません
                              ローカルにサーバが稼動していますか?
                              Unixドメインソケット"/var/run/postgresql/.s.PGSQL.5432"で通信を受け付けていますか?
2015-01-21 13:48:48,010 10.0.0.238 ec2-user fe_sendauth: no password supplied

Traceback (most recent call last):
  File "/usr/bin/fake2db", line 9, in <module>
    load_entry_point('fake2db==0.2.1', 'console_scripts', 'fake2db')()
  File "/usr/lib/python2.6/site-packages/fake2db/fake2db.py", line 122, in main
    fake_postgresql_handler.fake2db_postgresql_initiator(host, port, int(args.rows), str(args.name))
  File "/usr/lib/python2.6/site-packages/fake2db/postgresql_handler.py", line 32, in fake2db_postgresql_initiator
    self.data_filler_simple_registration(rows, cursor, conn)
  File "/usr/lib/python2.6/site-packages/fake2db/postgresql_handler.py", line 69, in data_filler_simple_registration
    cursor.execute("CREATE TABLE simple_registration (id serial PRIMARY KEY, email varchar(300), password varchar(300));")
AttributeError: 'NoneType' object has no attribute 'execute'

何か似たようなエラーが出ましたね。スクリプトの中身を見てみましょう。

/usr/lib/python2.6/site-packages/fake2db/postgresql_handler.py

import time
import getpass
import subprocess
import psycopg2

from helpers import fake2db_logger, str_generator

logger, extra_information = fake2db_logger()
d = extra_information

try:
    from faker import Factory
except ImportError:
    logger.error('faker package not found onto python packages, please run : \
    pip install -r requirements.txt  \
    on the root of the project')

......中略......

    def database_caller_creator(self, host, port, name=None):
        '''creates a postgresql db
        returns the related connection object
        which will be later used to spawn the cursor
        '''
        cursor = None
        conn = None
        username = getpass.getuser()

        try:
            if name:
                db = name
            else:
                db = 'postgresql_' + str_generator(self)

            subprocess.Popen("createdb --no-password --owner " + username + " " + db, shell=True)
            time.sleep(1)
            conn = psycopg2.connect("dbname=" + db + " user=" + username + " host=" + host + " port=" + port)
            cursor = conn.cursor()
            logger.warning('Database created and opened succesfully: %s' % db, extra=d)
        except Exception as err:
            logger.error(err, extra=d)

        return cursor, conn

......後略......

今度はgetpass.getuser()、つまりログイン名を取ってきているようです。更にここにはpasswordも無いようなのでここを修正してもう一回流してみます。

[ec2-user@ip-10-0-0-238 ~]$ fake2db --rows 200 --db postgresql --host test-postgres.XXXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com --password testtest --name test
2015-01-21 14:12:30,904 10.0.0.238 ec2-user Rows argument : 200
2015-01-21 14:12:30,934 10.0.0.238 ec2-user Your postgresql server is offline, fake2db will try to launch it now!
/bin/sh: postgres: コマンドが見つかりません
createdb: データベース template1 に接続できませんでした: サーバに接続できませんでした: そのようなファイルやディレクトリはありません
                              ローカルにサーバが稼動していますか?
                              Unixドメインソケット"/var/run/postgresql/.s.PGSQL.5432"で通信を受け付けていますか?
2015-01-21 14:12:34,964 10.0.0.238 ec2-user Database created and opened succesfully: test
2015-01-21 14:12:35,178 10.0.0.238 ec2-user simple_registration Commits are successful after write job!
2015-01-21 14:12:35,341 10.0.0.238 ec2-user detailed_registration Commits are successful after write job!
2015-01-21 14:12:35,507 10.0.0.238 ec2-user companies Commits are successful after write job!
2015-01-21 14:12:35,636 10.0.0.238 ec2-user user_agent Commits are successful after write job!
2015-01-21 14:12:35,823 10.0.0.238 ec2-user customer Commits are successful after write job!
[ec2-user@ip-10-0-0-238 ~]$

入ったようです。確認してみます。

[ec2-user@ip-10-0-0-238 ~]$ psql -h test-postgres.XXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com -Utestユーザ test のパスワード:
psql (9.2.9, サーバー 9.3.5)
注意: psql バージョン 9.2, サーバーバージョン 9.3.
         psql の機能の中で、動作しないものがあるかもしれません。
SSL 接続 (暗号化方式: DHE-RSA-AES256-SHA, ビット長: 256)
"help" でヘルプを表示します.

test=> \d
                      リレーションの一覧
 スキーマ |             名前             |     型     | 所有者
----------+------------------------------+------------+--------
 public   | company                      | テーブル   | test
 public   | company_id_seq               | シーケンス | test
 public   | customer                     | テーブル   | test
 public   | customer_id_seq              | シーケンス | test
 public   | detailed_registration        | テーブル   | test
 public   | detailed_registration_id_seq | シーケンス | test
 public   | simple_registration          | テーブル   | test
 public   | simple_registration_id_seq   | シーケンス | test
 public   | user_agent                   | テーブル   | test
 public   | user_agent_id_seq            | シーケンス | test
(10 行)

test=> select count(*) from company;
 count
-------
   200
(1 行)

test=>

ダミーデータが入っていることが確認できました。

まとめ

いかがでしたでしょうか。ワンライナーでダミーデータが作れるのは非常にラクでよいですね。 尚、データの中身はメアド、名前、住所等一般的なものは大体網羅しています。入れるテーブルの構成等も上で確認したスクリプトにかかれていますので、必要なデータを直接入れたい、ということであればこのスクリプトを変更すればその形で入ります。例えばmysqlのテーブル構成は

/usr/lib/python2.6/site-packages/fake2db/mysql_handler.py

   def mysql_table_creator(self):
        '''Create all the tables in one method
        '''
        tables = {}

        tables['simple_registration'] = (
            "CREATE TABLE `simple_registration` ("
            "  `id` varchar(300) NOT NULL,"
            "  `email` varchar(300) NOT NULL,"
            "  `password` varchar(300) NOT NULL,"
            "  PRIMARY KEY (`id`)"
            ") ENGINE=InnoDB")

        tables['detailed_registration'] = (
            "CREATE TABLE `detailed_registration` ("
            "  `id` varchar(300) NOT NULL,"
            "  `email` varchar(300) NOT NULL,"
            "  `password` varchar(300) NOT NULL,"
            "  `lastname` varchar(300) NOT NULL,"
            "  `name` varchar(300) NOT NULL,"
            "  `address` varchar(300) NOT NULL,"
            "  `phone` varchar(300) NOT NULL,"
            "  PRIMARY KEY (`id`)"
            ") ENGINE=InnoDB")

        tables['user_agent'] = (
            "CREATE TABLE `user_agent` ("
            "  `id` varchar(300) NOT NULL,"
            "  `ip` varchar(300) NOT NULL,"
            "  `countrycode` varchar(300) NOT NULL,"
            "  `useragent` varchar(300) NOT NULL,"
            "  PRIMARY KEY (`id`)"
            ") ENGINE=InnoDB")

        tables['company'] = (
            "CREATE TABLE `company` ("
            "  `id` varchar(300) NOT NULL,"
            "  `name` varchar(300) NOT NULL,"
            "  `sdate` date NOT NULL,"
            "  `email` varchar(300) NOT NULL,"
            "  `domain` varchar(300) NOT NULL,"
            "  `city` varchar(300) NOT NULL,"
            "  PRIMARY KEY (`id`)"
            ") ENGINE=InnoDB")

        tables['customer'] = (
            "CREATE TABLE `customer` ("
            "  `id` varchar(300) NOT NULL,"
            "  `name` varchar(300) NOT NULL,"
            "  `lastname` varchar(300) NOT NULL,"
            "  `address` varchar(300) NOT NULL,"
            "  `country` varchar(300) NOT NULL,"
            "  `city` varchar(300) NOT NULL,"
            "  `registry_date` varchar(300) NOT NULL,"
            "  `birthdate` varchar(300) NOT NULL,"
            "  `email` varchar(300) NOT NULL,"
            "  `phone_number` varchar(300) NOT NULL,"
            "  `locale` varchar(300) NOT NULL,"
            "  PRIMARY KEY (`id`)"
            ") ENGINE=InnoDB")

        return tables

ここになりますので、ここを修正すればOKですね。色々触ってカスタマイズして使いましょう。