000-platform-init.xml 14.6 KB
<?xml version="1.0" encoding="UTF-8"?>
<!--
  vibe_erp — platform init changelog.

  Creates the cross-cutting platform tables: an audit log and the
  metadata__* registry tables described in architecture spec section 8
  ("The metadata store").

  These are intentionally minimal v0.1 stubs: id + source + timestamps
  + (where useful) a payload jsonb. Real columns are added by later
  changesets in the PBCs that own them. pbc-identity owns the User
  schema and ships its own changelog.

  vibe_erp is single-tenant per instance: one running process serves
  exactly one company against an isolated database. There are no
  tenant_id columns and no Row-Level Security policies anywhere in
  this changelog — customer isolation happens at the deployment level
  (one running instance per customer).
-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                                       https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd">

    <!-- ─── platform__audit ──────────────────────────────────────────── -->
    <changeSet id="platform-init-001" author="vibe_erp">
        <createTable tableName="platform__audit">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="platform__audit" indexName="platform__audit_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="platform__audit"/></rollback>
    </changeSet>

    <!-- ─── metadata__entity ─────────────────────────────────────────── -->
    <changeSet id="platform-init-002" author="vibe_erp">
        <createTable tableName="metadata__entity">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__entity" indexName="metadata__entity_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__entity"/></rollback>
    </changeSet>

    <!-- ─── metadata__custom_field ───────────────────────────────────── -->
    <changeSet id="platform-init-003" author="vibe_erp">
        <createTable tableName="metadata__custom_field">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__custom_field" indexName="metadata__custom_field_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__custom_field"/></rollback>
    </changeSet>

    <!-- ─── metadata__form ───────────────────────────────────────────── -->
    <changeSet id="platform-init-004" author="vibe_erp">
        <createTable tableName="metadata__form">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__form" indexName="metadata__form_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__form"/></rollback>
    </changeSet>

    <!-- ─── metadata__list_view ──────────────────────────────────────── -->
    <changeSet id="platform-init-005" author="vibe_erp">
        <createTable tableName="metadata__list_view">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__list_view" indexName="metadata__list_view_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__list_view"/></rollback>
    </changeSet>

    <!-- ─── metadata__workflow ───────────────────────────────────────── -->
    <changeSet id="platform-init-006" author="vibe_erp">
        <createTable tableName="metadata__workflow">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__workflow" indexName="metadata__workflow_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__workflow"/></rollback>
    </changeSet>

    <!-- ─── metadata__rule ───────────────────────────────────────────── -->
    <changeSet id="platform-init-007" author="vibe_erp">
        <createTable tableName="metadata__rule">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__rule" indexName="metadata__rule_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__rule"/></rollback>
    </changeSet>

    <!-- ─── metadata__permission ─────────────────────────────────────── -->
    <changeSet id="platform-init-008" author="vibe_erp">
        <createTable tableName="metadata__permission">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__permission" indexName="metadata__permission_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__permission"/></rollback>
    </changeSet>

    <!-- ─── metadata__role_permission ────────────────────────────────── -->
    <changeSet id="platform-init-009" author="vibe_erp">
        <createTable tableName="metadata__role_permission">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__role_permission" indexName="metadata__role_permission_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__role_permission"/></rollback>
    </changeSet>

    <!-- ─── metadata__menu ───────────────────────────────────────────── -->
    <changeSet id="platform-init-010" author="vibe_erp">
        <createTable tableName="metadata__menu">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__menu" indexName="metadata__menu_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__menu"/></rollback>
    </changeSet>

    <!-- ─── metadata__report ─────────────────────────────────────────── -->
    <changeSet id="platform-init-011" author="vibe_erp">
        <createTable tableName="metadata__report">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__report" indexName="metadata__report_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__report"/></rollback>
    </changeSet>

    <!-- ─── metadata__translation ────────────────────────────────────── -->
    <changeSet id="platform-init-012" author="vibe_erp">
        <createTable tableName="metadata__translation">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__translation" indexName="metadata__translation_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__translation"/></rollback>
    </changeSet>

    <!-- ─── metadata__plugin_config ──────────────────────────────────── -->
    <changeSet id="platform-init-013" author="vibe_erp">
        <createTable tableName="metadata__plugin_config">
            <column name="id" type="uuid"><constraints primaryKey="true" nullable="false"/></column>
            <column name="source" type="varchar(32)" defaultValue="core"><constraints nullable="false"/></column>
            <column name="payload" type="jsonb"/>
            <column name="created_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
            <column name="updated_at" type="timestamptz" defaultValueComputed="now()"><constraints nullable="false"/></column>
        </createTable>
        <createIndex tableName="metadata__plugin_config" indexName="metadata__plugin_config_source_idx">
            <column name="source"/>
        </createIndex>
        <rollback><dropTable tableName="metadata__plugin_config"/></rollback>
    </changeSet>

</databaseChangeLog>