Git Product home page Git Product logo

carbon's People

Contributors

nojima avatar

Watchers

 avatar  avatar  avatar

carbon's Issues

VCS サービスの作成

設計

内部的なデータ構造は、git のデータ構造を真似る。すなわち

  • 歴史はオブジェクトのグラフとして表現される。
  • オブジェクトは以下の3種類:
    • blob - ページの内容を保持するオブジェクト。タイトルとタグもこれが持つ。
    • tree - blob の集合を保持するオブジェクト。名前は要検討。
    • commit - ある時点でのフォルダを表すオブジェクト。tree を持つ。
  • RDB 的には tree と blob の結合テーブルや、blob と tag の結合テーブルを持つ必要がある。
  • git のブランチ的なものを表現するために commit への参照を表現する reference オブジェクトを定義する。

したがって、スキーマは以下のようになる:

CREATE TABLE commits (
    id INTEGER NOT NULL,
    user_id INTEGER NOT NULL REFERENCES users (id) ON DELETE RESTRICT,
    created_at DATETIME NOT NULL,
    parent1_id INTEGER,
    parent2_id INTEGER,
    message TEXT,

    PRIMARY KEY (id, folder_id)
);

CREATE TABLE blobs (
    id INTEGER NOT NULL,
    document_id INTEGER NOT NULL REFERENCES documents (id) ON DELETE RESTRICT,
    title TEXT NOT NULL,
    content TEXT NOT NULL,

    PRIMARY KEY (id, folder_id)
);

CREATE TABLE documents (
    id INTEGER NOT NULL,

    PRIMARY KEY (id, folder_id)
);

CREATE TABLE tags (
    id INTEGER NOT NULL,
    name VARCHAR(255) NOT NULL,

    PRIMARY KEY (id, folder_id)
);

CREATE TABLE links (
    commit_id INTEGER NOT NULL REFERENCES commits (id) ON DELETE CASCADE,
    blob_id INTEGER NOT NULL REFERENCES blobs (id) ON DELETE CASCADE,

    PRIMARY KEY (commit_id, blob_id, folder_id)
);

CREATE TABLE taggings (
    blob_id INTEGER NOT NULL REFERENCES blobs (id) ON DELETE CASCADE,
    tag_id INTEGER NOT NULL REFERENCES tags (id) ON DELETE CASCADE,

    PRIMARY KEY (blob_id, tag_id, folder_id)
);

CREATE TABLE references (
    id INTEGER NOT NULL,
    folder_id INTEGER NOT NULL REFERENCES folders (id) ON DELETE CASCADE,
    commit_id INTEGER NOT NULL REFERENCES commits (id) ON DELETE CASCADE,
    name VARCHAR(255) NOT NULL,

    PRIMARY KEY (id, folder_id)
);
  • 更新がある場合は過去の blob を書き換えるのではなく、新しい blob と commit を作成する。
  • 非常に富豪的な感じのデータ構造だが、とりあえずは大丈夫だろう。たぶん。
  • 分散VCSではないので、id は連番でOK.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.