This script is currently in progress.
💡
This command assumes that the enviroment variable NOTION_API_KEY contains your integration key. Please set this environment variable before execution.
 

How to use

erdToNotionDb.rb creates Notion databases from ER diagrams in mermaid code block. At first, you invite your integration to your pages
  • a page including the mermaid code block,
  • a page for creating or updating databases.
After inviting, please type command as follows.

Format of ER diagram for creating Notion database

1. Database title

  • The first line is erDiagram
  • In Notion databases, titles often include non-ASCII characters such as spaces, symbols, and CJK characters. To ensure accuracy, please use keywords for Mermaid database titles.
  • Instead, enter the Database title in the comment field of the attribute.
  • The title property is required in the Notion database. Please make sure to provide one.
 
If you run the script in this state, it will be like this.
⚒️
Created database
notion image

2. Update database

  • If there is already corresponding database on the page, it will be updated.
  • The title can only exist once in the database, so it will change if it is rewritten.
  • When creating databases in Notion, property names may include non-ASCII characters such as spaces, symbols, and CJK characters. To ensure accuracy, please use keywords for Mermaid attribute names and enter the property name in the comment field of the attribute.
    • ⚒️
      Updated title
      notion image

3. Add other properties (without relation and rollup)

  • You can add properties other than the title. The following types are set without any options.
    • checkbox
    • created_by
    • created_time
    • date
    • email
    • files
    • last_edited_by
    • last_edited_time
    • people
    • phone_number
    • rich_text
    • url
    • status
  • The following properties can be specified with an option. The option is written after the |.
    • formula|formula_expression
      • ex1: formula … formula without expression
      • ex2: formula|now()
      • ex3: prop(@Progress@) … Please use @ instead.
    • multi_select|selection_name1|selection_name2…
      • ex1: multi_select … multi_select without selections
      • ex2: multi_select|SEL1|SEL2|SEL3
    • number|format
      • ex1: number … number with "number"
      • ex2: number|percent
    • select|selection_name1|selection_name2…
      • ex1: select … multi_select without selections
      • ex2: select|SEL1|SEL2|SEL3
      ⚒️
      Add date and status properties
      notion image

4. Add a second database and establish a relationship between them.

  • The page limit of the database cannot be set with the API, so any symbol is fine.
  • When the name of the relation is separated by a |, a bidirectional relation is created.
    • ⚒️
      Created bidirectional relation
      notion image

5. Add rollup property

Finally, I will explain how to create a roll-up. In the case of a roll-up, the comment field should be written in the order of "property name | relation name | roll-up name | function". The available functions are as follows.
average, checked, count, count_per_group, count_values, date_range, earliest_date, empty, latest_date, max, median, min, not_empty, percent_checked, percent_empty, percent_not_empty, percent_per_group, percent_unchecked, range, show_original, show_unique, sum, unchecked, unique,
⚒️
Created database
notion image
 

Limitation

  1. You cannot set the Status property through the API, so please convert it to another property first and then convert it back to Status.
  1. Settings with dependencies cannot be created at once. We have made it possible to create Relations with Rollup at the same time as setting. We plan to update the script taking into account the dependencies. → I released erdToNotionDb to correspond to dependencies. If there were dependencies, it would block and try to generate in the next pass.
 

Mermaid sample 1

 

Generated tables 1

Task database
Task name
Date
Done
Project progress
project
Project
Project name
Progress
_Progress
tasks

Mermaid sample 2

Generated tables 2

タスク
タスク名
プロジェクト完了率
完了
プロジェクト
日付
Loading...