前回のエントリでER図作成ツールを作りたい旨書きましたが、今回はもろもろ準備を進めていきます。
package.json
ホントにリポジトリ作っただけで、まだpackage.jsonすら置いてなかったので npm init
します。
あと、nodeでコマンドラインツールを作ろうとする場合にはなんか設定が必要らしいので調べつつ設定を弄っていきます。
どうやらbinに指定したスクリプトがコマンドラインでのエントリポイントになるようです。
{
"name": "openerd",
"version": "1.0.0",
"description": "Generate ER Diagram from yaml",
"main": "index.js",
"bin": "cli/index.js",
"scripts": {},
"repository": {
"type": "git",
"url": "https://github.com/yosiopp/openerd.git"
},
"keywords": [
"OpenERD",
"erd",
"yaml",
"cli"
],
"author": "yosiopp",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/yosiopp/openerd/issues"
},
"homepage": "https://github.com/yosiopp/openerd#readme"
}
こんな感じにしました。
不足点などは気付き次第修正してくことにします。
schema
openerd: 1.0.0
info:
title: string
version: string
description: string
contact:
name: string
url: string
email: string
database: [mysql]
entities:
- name: string
summary: string
tag: string
attributes:
- name: string
summary: string
type: string
primary: boolean
required: boolean
default: string
options:
- string
relations:
- target: string
reference: string
cardinality: string
layout:
x: integer
y: integer
color: string
indecies:
- name: string
unique: boolean
fields:
- string
layout:
x: integer
y: integer
width: integer
height: integer
color: string
elevation: integer
tags:
- string
options:
string: string
ざっくりこんな感じのフォーマットにしようと思ってます。OpenAPI Specインスパイア。
これをJSON Schema(yaml)で定義するとこんなかんじ。
type: object
required: [openerd]
properties:
openerd:
type: string
pattern: "^1\\.0\\.0$"
info:
type: object
properties:
title:
type: string
version:
type: string
description:
type: string
contact:
type: object
properties:
name:
type: string
url:
type: string
email:
type: string
database:
type: array
items:
type: string
pattern: "mysql"
entities:
type: array
items:
type: object
required: [name]
properties:
name:
type: string
summary:
type: string
tag:
type: string
attributes:
type: array
items:
type: object
required: [name, type]
properties:
name:
type: string
summary:
type: string
type:
type: string
primary:
type: boolean
required:
type: boolean
default:
type: string
options:
type: array
items:
type: string
relations:
type: array
items:
type: object
properties:
target:
type: string
reference:
type: string
cardinality:
type: string
pattern: "^(1|0\\.\\.1|1\\.\\.\\*|0\\.\\.\\*)-(1|0\\.\\.1|1\\.\\.\\*|0\\.\\.\\*)$"
layout:
type: object
properties:
x:
type: number
minimum: 0
y:
type: number
minimum: 0
color:
type: string
pattern: "^#[0-9a-fA-F]{6}$"
indecies:
type: array
items:
type: object
required: [name, fields]
properties:
name:
type: string
unique:
type: boolean
fields:
type: array
items:
type: string
layout:
type: object
properties:
x:
type: number
minimum: 0
y:
type: number
minimum: 0
width:
type: number
minimum: 1
height:
type: number
minimum: 1
color:
type: string
pattern: "^#[0-9a-fA-F]{6}$"
elevation:
type: number
tags:
type: array
items:
type: string
options:
type: object
patternProperties: "^[a-zA-Z][-a-zA-Z0-9]*$"
各プロパティの説明は書いてないですが、なんとなく雰囲気伝わるでしょうか。
ちなみに、entitiesにテーブル定義が書かれるイメージなのですが、OASのpathsのようにobject型にしなかったのは、DDLにした時のテーブルの並び順を変えられるようにしたかったからです。