きょこみのーと

技術に関係ないほうのブログ

sqlをER図で表示するならSQLEditorがよさそう

Play Frameworkいいですよね。

Modelクラスから自動でSQL生成してくれてて気持ちいい。

しかし、ER図みて全体を俯瞰したいなーというときにちょっと調べたら、SQL Editorってのがあって、よさそうな感じでした。

実際に使ってみたのはMac版です。Windows版もあるっぽいけど使ってないのでちょっとわかりません。

元になったSQL

Play Frameworkのebeanの場合evolutionしたsqlは以下のパスにあります。

{MyProject}/conf/evolutions/default

# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions

# --- !Ups

create table accounts (
  id                        bigint not null,
  username                  varchar(255),
  password                  varchar(255),
  created                   timestamp not null,
  modified                  timestamp not null,
  constraint pk_accounts primary key (id))
;

create table tasks (
  id                        bigint not null,
  taskname                  varchar(255),
  taskdetail                varchar(255),
  startdate                 timestamp,
  enddate                   timestamp,
  account_id                bigint,
  created                   timestamp not null,
  modified                  timestamp not null,
  constraint pk_tasks primary key (id))
;

create table task_historys (
  id                        bigint not null,
  comment                   varchar(255),
  task_id                   bigint,
  created                   timestamp not null,
  modified                  timestamp not null,
  constraint pk_task_historys primary key (id))
;

create sequence accounts_seq;

create sequence tasks_seq;

create sequence task_historys_seq;

alter table tasks add constraint fk_tasks_account_1 foreign key (account_id) references accounts (id) on delete restrict on update restrict;
create index ix_tasks_account_1 on tasks (account_id);
alter table task_historys add constraint fk_task_historys_task_2 foreign key (task_id) references tasks (id) on delete restrict on update restrict;
create index ix_task_historys_task_2 on task_historys (task_id);



# --- !Downs

SET REFERENTIAL_INTEGRITY FALSE;

drop table if exists accounts;

drop table if exists tasks;

drop table if exists task_historys;

SET REFERENTIAL_INTEGRITY TRUE;

drop sequence if exists accounts_seq;

drop sequence if exists tasks_seq;

drop sequence if exists task_historys_seq;

drop文とか余裕で混ざってます。

SQLEditorでimportしてみる

起動して File -> Import From File ... を選択

f:id:kyokomi:20140401175855p:plain

対象のsqlファイルを開く

f:id:kyokomi:20140401175903p:plain

こうなる

f:id:kyokomi:20140401175840p:plain

わ~素敵。まあimportして表示するだけなら他にもあるのかな?

何かおすすめあれば教えてください!