텍스트 기반 데이터베이스 정의 관리 도구erdm 만들기

14561 단어 GraphvizGoPEGER 그림

텍스트 기반 데이터베이스 정의 관리 도구erdm 만들기


개요


특정 형식으로 설명된 파일을 변환하여 간단한 ER 그림과 HTML 기반 정의서를 만들 수 있습니다.
또 DDL을 제작할 수도 있다.(PostgreSQL, SQLite용)

다운로드


아래 페이지에서 최신 버전을 다운로드하여 사용하십시오.
https://github.com/unok/erdm/releases

예제


erdm 파일


변환할 텍스트 파일입니다.
# Title: Shopping Site

users/顧客
    +id/顧客ID [bigserial][NN][U]
    name/名称 [varchar(128)][NN][='']
    password/パスワード [varchar(128)][='********']
        # sha1 でハッシュ化して登録
    mail_address/メールアドレス [varchar(256)][NN][U]
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]
    index i_users_mail_address (mail_address)

prefectures/都道府県
    +id/都道府県ID [int][NN][U]
    name/都道府県名称 [varchar(4)][NN][U]
    sort_order/ソート順 [int][NN][U]

address_types/住所種別
    +id/住所種別ID [int][NN][U]
    name/種別名称 [varchar(10)][NN][U]

addresses/住所
    +id/住所ID [bigserial][NN][U]
    user_id/顧客ID [bigint][NN] 0..*--1 users
    name/名称 [varchar(128)][NN]
    address_type_id/住所種別ID [bigint] 0..*--1 address_types
    post_code/郵便番号 [varchar(7)][NN]
    prefecture_id/都道府県コード [bigint][NN] 0..*--1 prefectures
    address1/住所1 [varchar(128)][NN]
    address2/住所2 [varchar(128)]
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]
    index i_addresses_user_id (user_id)
    index i_addresses_address_type_id (address_type_id)
    index i_addresses_prefecture_id (prefecture_id)

items/商品
    +id/商品ID [bigserial][NN][U]
    name/商品名 [varchar(128)][NN]
    description/詳細 [text]
    quantity/数量 [int][NN]
    price/単価 [numeric(10,2)][NN]
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]

carts/カート
    +id/カートID [bigserial][NN][U]
    user_id/顧客ID [bigint][NN] 0..*--1 users
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]
    index i_carts_user_id (user_id)

cart_items/カート内アイテム
    +id/カート内アイテムID [bigserial][NN][U]
    cart_id/カートID [bigint][NN] 0..*--1 carts
    item_id/商品ID [bigint][NN] 0..*--1 items
    category_id/分類ID [bigint][NN][U] 0..*--1 categories
    quantity/数量 [int][NN]
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]
    index i_cart_items_cart_id (cart_id)

orders/注文
    +id/注文ID [bigserial][NN][U]
    cart_id/カートID [bigint][NN] 0..*--1 carts
    order_status/注文状態 [int][NN][=0]
    order_time/発注日時 [timestamp with time zone][NN][=now()]
    shipment_time/出荷日時 [timestamp with time zone][NN][=now()]
    shipment_user_id/出荷担当者 [bigint] 0..*--1 administrators
    track_no/送り状番号 [varchar(64)]
    user_id/顧客ID [bigint][NN] 0..*--1 users
    item_id/商品ID [bigint][NN] 0..*--1 items
    category_id/分類ID [bigint][NN][U] 0..*--1 categories
    order_address_id/発注者住所 [bigint][NN] 0..*--1 addresses
    delivery_address_id/納品先住所 [bigint][NN] 0..*--1 addresses
    charge_address_id/請求先住所 [bigint][NN] 0..*--1 addresses
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]
    index i_orders_cart_id (cart_id)
    index i_orders_user_id (user_id)
    index i_orders_item_id (item_id)
    index i_orders_cart_id_item_id (cart_id, item_id) unique

categories/分類
    +id/分類ID [bigserial][NN][U]
    name/タグ [varchar(128)][NN]
    description/説明 [text]
    parent_category_id/親分類ID [bigint] 0..*--0..1 categories
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]

item_categories/商品分類
    +id/商品分類ID [bigserial][NN][U]
    item_id/商品ID [bigint][NN] 0..*--1 items
    category_id/分類ID [bigint][NN][U] 0..*--1 categories

administrators/管理者
    +id/管理者ID [bigserial][NN][U]
    name/管理者名称 [varchar(64)][NN][U]
    login_name/ログイン名 [varchar(64)][NN][U]
    mail_address/メールアドレス [varchar(256)][NN][U]
    password/パスワード [varchar(128)][='********']
      # sha1 でハッシュ化して登録
    updated/更新日時 [timestamp with time zone][NN][=now()][-erd]
    created/作成日時 [timestamp with time zone][NN][=now()][-erd]

ER 그림



정의서 HTML


AngulerJS 1.2.x 검색 기능이 있는 데이터베이스 정의서입니다.

DDL


PostgreSQL

DROP TABLE IF EXISTS users CASCADE;
DROP TABLE IF EXISTS prefectures CASCADE;
DROP TABLE IF EXISTS address_types CASCADE;
DROP TABLE IF EXISTS addresses CASCADE;
DROP TABLE IF EXISTS items CASCADE;
DROP TABLE IF EXISTS carts CASCADE;
DROP TABLE IF EXISTS cart_items CASCADE;
DROP TABLE IF EXISTS orders CASCADE;
DROP TABLE IF EXISTS categories CASCADE;
DROP TABLE IF EXISTS item_categories CASCADE;
DROP TABLE IF EXISTS administrators CASCADE;


CREATE TABLE users (
    id bigserial UNIQUE NOT NULL,
    name varchar(128) NOT NULL DEFAULT '',
    password varchar(128) DEFAULT '********',
    mail_address varchar(256) UNIQUE NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_users_mail_address ON users (mail_address);

CREATE TABLE prefectures (
    id int UNIQUE NOT NULL,
    name varchar(4) UNIQUE NOT NULL,
    sort_order int UNIQUE NOT NULL,

    PRIMARY KEY (id)
);

CREATE TABLE address_types (
    id int UNIQUE NOT NULL,
    name varchar(10) UNIQUE NOT NULL,

    PRIMARY KEY (id)
);

CREATE TABLE addresses (
    id bigserial UNIQUE NOT NULL,
    user_id bigint NOT NULL,
    name varchar(128) NOT NULL,
    address_type_id bigint,
    post_code varchar(7) NOT NULL,
    prefecture_id bigint NOT NULL,
    address1 varchar(128) NOT NULL,
    address2 varchar(128),
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_addresses_user_id ON addresses (user_id);
CREATE INDEX i_addresses_address_type_id ON addresses (address_type_id);
CREATE INDEX i_addresses_prefecture_id ON addresses (prefecture_id);

CREATE TABLE items (
    id bigserial UNIQUE NOT NULL,
    name varchar(128) NOT NULL,
    description text,
    quantity int NOT NULL,
    price numeric(10,2) NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);

CREATE TABLE carts (
    id bigserial UNIQUE NOT NULL,
    user_id bigint NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_carts_user_id ON carts (user_id);

CREATE TABLE cart_items (
    id bigserial UNIQUE NOT NULL,
    cart_id bigint NOT NULL,
    item_id bigint NOT NULL,
    category_id bigint UNIQUE NOT NULL,
    quantity int NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_cart_items_cart_id ON cart_items (cart_id);

CREATE TABLE orders (
    id bigserial UNIQUE NOT NULL,
    cart_id bigint NOT NULL,
    order_status int NOT NULL DEFAULT 0,
    order_time timestamp with time zone NOT NULL DEFAULT now(),
    shipment_time timestamp with time zone NOT NULL DEFAULT now(),
    shipment_user_id bigint,
    track_no varchar(64),
    user_id bigint NOT NULL,
    item_id bigint NOT NULL,
    category_id bigint UNIQUE NOT NULL,
    order_address_id bigint NOT NULL,
    delivery_address_id bigint NOT NULL,
    charge_address_id bigint NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_orders_cart_id ON orders (cart_id);
CREATE INDEX i_orders_user_id ON orders (user_id);
CREATE INDEX i_orders_item_id ON orders (item_id);
CREATE UNIQUE INDEX i_orders_cart_id_item_id ON orders (cart_id, item_id);

CREATE TABLE categories (
    id bigserial UNIQUE NOT NULL,
    name varchar(128) NOT NULL,
    description text,
    parent_category_id bigint,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);

CREATE TABLE item_categories (
    id bigserial UNIQUE NOT NULL,
    item_id bigint NOT NULL,
    category_id bigint UNIQUE NOT NULL,

    PRIMARY KEY (id)
);

CREATE TABLE administrators (
    id bigserial UNIQUE NOT NULL,
    name varchar(64) UNIQUE NOT NULL,
    login_name varchar(64) UNIQUE NOT NULL,
    mail_address varchar(256) UNIQUE NOT NULL,
    password varchar(128) DEFAULT '********',
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);

SQLite

DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS prefectures;
DROP TABLE IF EXISTS address_types;
DROP TABLE IF EXISTS addresses;
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS carts;
DROP TABLE IF EXISTS cart_items;
DROP TABLE IF EXISTS orders;
DROP TABLE IF EXISTS categories;
DROP TABLE IF EXISTS item_categories;
DROP TABLE IF EXISTS administrators;


CREATE TABLE users (
    id bigserial UNIQUE NOT NULL,
    name varchar(128) NOT NULL DEFAULT '',
    password varchar(128) DEFAULT '********',
    mail_address varchar(256) UNIQUE NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_users_mail_address ON users (mail_address);

CREATE TABLE prefectures (
    id int UNIQUE NOT NULL,
    name varchar(4) UNIQUE NOT NULL,
    sort_order int UNIQUE NOT NULL,

    PRIMARY KEY (id)
);

CREATE TABLE address_types (
    id int UNIQUE NOT NULL,
    name varchar(10) UNIQUE NOT NULL,

    PRIMARY KEY (id)
);

CREATE TABLE addresses (
    id bigserial UNIQUE NOT NULL,
    user_id bigint NOT NULL,
    name varchar(128) NOT NULL,
    address_type_id bigint,
    post_code varchar(7) NOT NULL,
    prefecture_id bigint NOT NULL,
    address1 varchar(128) NOT NULL,
    address2 varchar(128),
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_addresses_user_id ON addresses (user_id);
CREATE INDEX i_addresses_address_type_id ON addresses (address_type_id);
CREATE INDEX i_addresses_prefecture_id ON addresses (prefecture_id);

CREATE TABLE items (
    id bigserial UNIQUE NOT NULL,
    name varchar(128) NOT NULL,
    description text,
    quantity int NOT NULL,
    price numeric(10,2) NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);

CREATE TABLE carts (
    id bigserial UNIQUE NOT NULL,
    user_id bigint NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_carts_user_id ON carts (user_id);

CREATE TABLE cart_items (
    id bigserial UNIQUE NOT NULL,
    cart_id bigint NOT NULL,
    item_id bigint NOT NULL,
    category_id bigint UNIQUE NOT NULL,
    quantity int NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_cart_items_cart_id ON cart_items (cart_id);

CREATE TABLE orders (
    id bigserial UNIQUE NOT NULL,
    cart_id bigint NOT NULL,
    order_status int NOT NULL DEFAULT 0,
    order_time timestamp with time zone NOT NULL DEFAULT now(),
    shipment_time timestamp with time zone NOT NULL DEFAULT now(),
    shipment_user_id bigint,
    track_no varchar(64),
    user_id bigint NOT NULL,
    item_id bigint NOT NULL,
    category_id bigint UNIQUE NOT NULL,
    order_address_id bigint NOT NULL,
    delivery_address_id bigint NOT NULL,
    charge_address_id bigint NOT NULL,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);
CREATE INDEX i_orders_cart_id ON orders (cart_id);
CREATE INDEX i_orders_user_id ON orders (user_id);
CREATE INDEX i_orders_item_id ON orders (item_id);
CREATE UNIQUE INDEX i_orders_cart_id_item_id ON orders (cart_id, item_id);

CREATE TABLE categories (
    id bigserial UNIQUE NOT NULL,
    name varchar(128) NOT NULL,
    description text,
    parent_category_id bigint,
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);

CREATE TABLE item_categories (
    id bigserial UNIQUE NOT NULL,
    item_id bigint NOT NULL,
    category_id bigint UNIQUE NOT NULL,

    PRIMARY KEY (id)
);

CREATE TABLE administrators (
    id bigserial UNIQUE NOT NULL,
    name varchar(64) UNIQUE NOT NULL,
    login_name varchar(64) UNIQUE NOT NULL,
    mail_address varchar(256) UNIQUE NOT NULL,
    password varchar(128) DEFAULT '********',
    updated timestamp with time zone NOT NULL DEFAULT now(),
    created timestamp with time zone NOT NULL DEFAULT now(),

    PRIMARY KEY (id)
);

실행 방법


먼저 Graphiviz를 설치하고 경로를 통과하십시오.
그리고 다음 명령을 실행하면 출력 대상 폴더에 변환된 여러 파일을 만듭니다.
erdm -output_dir 出力先フォルダパス erdmファイルパス

기술을 이용하다


Go 언어로 구현됩니다.PEG를 erdm 파일의 파서로 사용합니다.
ER 그림 제작은 Graphiviz를 사용합니다.

발동기를 켜다


이 소프트웨어를 개발하는 동기는 다음과 같은 몇 가지가 있다.
  • 소스 코드처럼 차분 관리를 하고 싶다
  • Go 언어로 뭔가 하고 싶어
  • PEG
  • 쓰고 싶어요.
  • DSL 정의 연습
  • TODO

  • 정형열을 그룹으로 나누기(예를 들어created,creator,updated,updatter 등 그룹)
  • ER 그림을 테이블 이름으로만 설정하는 옵션(대부분의 테이블 수가 증가하여 읽을 수 있음)
  • ER 그림의 그룹과 분할(특정 그룹 단위로 관계 표시)
  • 잘못된 내용을 더 쉽게 해석하고 싶다
  • HTML의 디자인은 누가...
  • 최후


    방금 만든 따끈따끈한 소프트웨어니까 버그로 등록해 주세요.
    홍보도 기대하고 있다.

    좋은 웹페이지 즐겨찾기