Archituredocs

Import

Bring an existing PostgreSQL or MySQL database into Architure with the catalog query or a schema-only dump.

Import is how an existing database enters your architecture: its schemas, tables, keys, indexes, enum types and comments become a database of your organization, which your agents then read and write. There are two ways in. The catalog query is recommended: it asks the database itself, so types, defaults, comments and enum types arrive exactly as the database knows them. A schema-only dump works too, through a SQL parser.

You can import in two places:

  • The start screen of https://app.architure.dev/new, which starts a new draft without an account. Paste into Your schema and choose Open the diagram: a catalog query result is recognized as JSON and read in your browser, anything else is read as a dump. How to get your schema shows the query and the dump commands.
  • Import in the top bar of the canvas, in a database or a draft, which adds the imported objects to it. The Import a schema dialog asks for the Database (PostgreSQL or MySQL) and What you paste: Catalog query result or Schema dump (DDL). With the catalog query result, the dialog shows the query with a Copy button.

An import adds to the design; it does not compare. To bring a database that already has a connection back in line with its live schemas, use the schema sync, which previews what changes and keeps your positions, areas, information types and descriptions.

A database holds one dialect. Importing a schema of the other dialect works only while the database is empty, and the database's dialect changes with it.

Catalog query

The query is read-only. It reads only the system catalogs (names, types, keys, indexes, comments), never your rows, and returns one row with one JSON value named architure_catalog. Nothing is sent anywhere until you paste the result into Architure.

PostgreSQL

For PostgreSQL 12 or later. It reads pg_catalog only: schemas, enum types with their values in order, tables and partitioned tables, columns with their types, defaults, nullability and identity, primary keys, unique constraints, foreign keys with their actions, indexes, and comments.

It leaves out the system schemas (pg_catalog, information_schema, pg_toast and temporary schemas), the schemas and tables that extensions create, and the schemas Supabase manages (auth, storage, realtime and the others listed at the top of the query). To import one of those, delete its line from the list before running the query.

architure-catalog.sql (PostgreSQL)
-- Architure catalog query for PostgreSQL 12 or later.
-- Read-only: it reads the system catalogs and returns one JSON value (architure_catalog).
-- Copy that value into Architure's import dialog.
with excluded_schemas (name) as (
  values ('pg_catalog'), ('information_schema'), ('pg_toast'),
    -- Supabase's managed schemas: delete a line to import that schema too.
    ('auth'), ('storage'), ('realtime'), ('_realtime'), ('supabase_functions'),
    ('supabase_migrations'), ('extensions'), ('graphql'), ('graphql_public'), ('pgbouncer'),
    ('pgsodium'), ('pgsodium_masks'), ('vault'), ('net'), ('cron'), ('_analytics')
),
schemas as (
  select n.oid, n.nspname
  from pg_catalog.pg_namespace n
  where n.nspname not in (select name from excluded_schemas)
    and n.nspname not like 'pg\_temp\_%'
    and n.nspname not like 'pg\_toast\_temp\_%'
    -- Schemas created by an extension.
    and not exists (
      select 1 from pg_catalog.pg_depend d
      where d.classid = 'pg_catalog.pg_namespace'::regclass and d.objid = n.oid and d.deptype = 'e'
    )
),
tables as (
  select c.oid, c.relname, s.nspname
  from pg_catalog.pg_class c
  join schemas s on s.oid = c.relnamespace
  where c.relkind in ('r', 'p')
    -- Tables created by an extension.
    and not exists (
      select 1 from pg_catalog.pg_depend d
      where d.classid = 'pg_catalog.pg_class'::regclass and d.objid = c.oid and d.deptype = 'e'
    )
)
select json_build_object(
  'format', 'architure-catalog',
  'version', 1,
  'dialect', 'postgresql',
  'server_version', current_setting('server_version_num'),
  'database', current_database(),
  'schemas', coalesce((
    select json_agg(json_build_object(
      'name', s.nspname,
      'comment', pg_catalog.obj_description(s.oid, 'pg_namespace')
    ) order by s.nspname)
    from schemas s
  ), '[]'::json),
  'enums', coalesce((
    select json_agg(json_build_object(
      'schema', s.nspname,
      'name', t.typname,
      'values', (
        select json_agg(e.enumlabel order by e.enumsortorder)
        from pg_catalog.pg_enum e where e.enumtypid = t.oid
      ),
      'comment', pg_catalog.obj_description(t.oid, 'pg_type')
    ) order by s.nspname, t.typname)
    from pg_catalog.pg_type t
    join schemas s on s.oid = t.typnamespace
    where t.typtype = 'e'
  ), '[]'::json),
  'tables', coalesce((
    select json_agg(json_build_object(
      'schema', t.nspname,
      'name', t.relname,
      'comment', pg_catalog.obj_description(t.oid, 'pg_class'),
      'columns', coalesce((
        select json_agg(json_build_object(
          'name', a.attname,
          'position', a.attnum,
          'type', pg_catalog.format_type(a.atttypid, a.atttypmod),
          'type_schema', tn.nspname,
          'type_name', ty.typname,
          'type_kind', ty.typtype,
          'nullable', not a.attnotnull,
          'default', pg_catalog.pg_get_expr(ad.adbin, ad.adrelid),
          'identity', a.attidentity,
          'generated', a.attgenerated,
          'comment', pg_catalog.col_description(t.oid, a.attnum)
        ) order by a.attnum)
        from pg_catalog.pg_attribute a
        join pg_catalog.pg_type ty on ty.oid = a.atttypid
        join pg_catalog.pg_namespace tn on tn.oid = ty.typnamespace
        left join pg_catalog.pg_attrdef ad on ad.adrelid = a.attrelid and ad.adnum = a.attnum
        where a.attrelid = t.oid and a.attnum > 0 and not a.attisdropped
      ), '[]'::json),
      'constraints', coalesce((
        select json_agg(json_build_object(
          'name', con.conname,
          'type', con.contype,
          'columns', (
            select json_agg(a.attname order by k.ord)
            from unnest(con.conkey) with ordinality as k (attnum, ord)
            join pg_catalog.pg_attribute a on a.attrelid = con.conrelid and a.attnum = k.attnum
          ),
          'ref_schema', rn.nspname,
          'ref_table', rc.relname,
          'ref_columns', (
            select json_agg(a.attname order by k.ord)
            from unnest(con.confkey) with ordinality as k (attnum, ord)
            join pg_catalog.pg_attribute a on a.attrelid = con.confrelid and a.attnum = k.attnum
          ),
          'on_delete', con.confdeltype,
          'on_update', con.confupdtype
        ) order by con.conname)
        from pg_catalog.pg_constraint con
        left join pg_catalog.pg_class rc on rc.oid = con.confrelid
        left join pg_catalog.pg_namespace rn on rn.oid = rc.relnamespace
        -- Primary keys, unique constraints and foreign keys, not the copies on partitions.
        where con.conrelid = t.oid and con.contype in ('p', 'u', 'f') and con.conparentid = 0
      ), '[]'::json),
      'indexes', coalesce((
        select json_agg(json_build_object(
          'name', ic.relname,
          'unique', i.indisunique,
          -- null for an expression
          'columns', (
            select json_agg(a.attname order by k.ord)
            from unnest(i.indkey::int2[]) with ordinality as k (attnum, ord)
            left join pg_catalog.pg_attribute a on a.attrelid = i.indrelid and a.attnum = k.attnum
            where k.ord <= i.indnkeyatts
          ),
          'partial', i.indpred is not null
        ) order by ic.relname)
        from pg_catalog.pg_index i
        join pg_catalog.pg_class ic on ic.oid = i.indexrelid
        where i.indrelid = t.oid
          -- Not the indexes behind a primary key, unique or exclusion constraint.
          and not exists (
            select 1 from pg_catalog.pg_constraint con
            where con.conindid = i.indexrelid and con.contype in ('p', 'u', 'x')
          )
          -- Not the copies of a partitioned table's index.
          and not exists (
            select 1 from pg_catalog.pg_inherits inh where inh.inhrelid = i.indexrelid
          )
      ), '[]'::json)
    ) order by t.nspname, t.relname)
    from tables t
  ), '[]'::json)
) as architure_catalog;

Save the query as architure-catalog.sql and run it with psql. --no-align --tuples-only prints the JSON value alone, without a header or line markers:

psql "postgresql://user@host:5432/database" --no-psqlrc --no-align --tuples-only \
  --file architure-catalog.sql > catalog.json

In a SQL client (pgAdmin, DBeaver, TablePlus, DataGrip, the Supabase SQL editor), run the query and copy the single value of the result. Architure also reads the value when the client copies it with its column name or as a one-row JSON array. It does not read psql's default aligned output, which adds a + at the end of every line of the value: use the options above.

MySQL

For MySQL 8.0 or later. It reads information_schema for the current database only: its tables (not views), their columns with the full column type, default, nullability, extra attributes (auto_increment, on update CURRENT_TIMESTAMP) and comment, their indexes including the primary key, their foreign keys with their actions, and table comments. The database becomes the database's public schema.

architure-catalog.sql (MySQL)
-- Architure catalog query for MySQL 8.0 or later.
-- Read-only: it reads information_schema for the current database (run USE your_database first)
-- and returns one JSON value (architure_catalog). Copy that value into Architure's import dialog.
select json_object(
  'format', 'architure-catalog',
  'version', 1,
  'dialect', 'mysql',
  'server_version', version(),
  'database', database(),
  'tables', coalesce((
    select json_arrayagg(json_object(
      'name', t.table_name,
      'comment', t.table_comment,
      'columns', (
        select json_arrayagg(json_object(
          'name', c.column_name,
          'position', c.ordinal_position,
          'type', c.column_type,
          'data_type', c.data_type,
          'nullable', c.is_nullable,
          'default', c.column_default,
          'extra', c.extra,
          'comment', c.column_comment
        ))
        from information_schema.columns c
        where c.table_schema = t.table_schema and c.table_name = t.table_name
      ),
      'indexes', (
        select json_arrayagg(json_object(
          'name', s.index_name,
          'non_unique', s.non_unique,
          'position', s.seq_in_index,
          -- null for a functional key part
          'column', s.column_name,
          'type', s.index_type
        ))
        from information_schema.statistics s
        where s.table_schema = t.table_schema and s.table_name = t.table_name
      ),
      'foreign_keys', (
        select json_arrayagg(json_object(
          'name', k.constraint_name,
          'position', k.ordinal_position,
          'column', k.column_name,
          'ref_schema', k.referenced_table_schema,
          'ref_table', k.referenced_table_name,
          'ref_column', k.referenced_column_name,
          'on_delete', r.delete_rule,
          'on_update', r.update_rule
        ))
        from information_schema.key_column_usage k
        join information_schema.referential_constraints r
          on r.constraint_schema = k.constraint_schema
          and r.constraint_name = k.constraint_name
          and r.table_name = k.table_name
        where k.table_schema = t.table_schema and k.table_name = t.table_name
          and k.referenced_table_name is not null
      )
    ))
    from information_schema.tables t
    where t.table_schema = database() and t.table_type = 'BASE TABLE'
  ), json_array())
) as architure_catalog;

Run it against the database you want to import (MySQL calls a schema a database). --batch --raw --skip-column-names print the JSON value alone, without escaping:

mysql --host=host --user=user --password --batch --raw --skip-column-names \
  database < architure-catalog.sql > catalog.json

In a SQL client (MySQL Workbench, DBeaver, TablePlus, DataGrip), select the database first (USE database;), run the query and copy the single value of the result.

Paste the result

On the start screen of https://app.architure.dev/new, paste the JSON (the content of catalog.json) into Your schema. On the canvas, choose Import, then Catalog query result, and paste it under 2. Paste the JSON it returned. The diagram appears.

Schema-only dump

Paste the SQL that creates your schema. The usual way to get it:

PostgreSQL
pg_dump --schema-only --no-owner --no-privileges \
  "postgresql://user@host:5432/database" > schema.sql
MySQL
mysqldump --no-data --skip-comments --host=host --user=user --password database > schema.sql

Any file of CREATE statements works, such as your migrations squashed into one file. A dump is read on Architure's server, up to 1 MB at a time.

What the PostgreSQL import reads:

  • CREATE SCHEMA, and CREATE TABLE with columns, defaults, NOT NULL, PRIMARY KEY, UNIQUE and REFERENCES;
  • ALTER TABLE ... ADD CONSTRAINT, including the ALTER TABLE ONLY statements pg_dump writes;
  • CREATE INDEX and CREATE UNIQUE INDEX;
  • CREATE TYPE ... AS ENUM;
  • identity columns, serial types and nextval(...) defaults, read as auto-increment;
  • COMMENT ON SCHEMA, COMMENT ON TABLE and COMMENT ON COLUMN, read as descriptions.

What the MySQL import reads: CREATE TABLE with columns (UNSIGNED included), defaults with their ON UPDATE, keys, indexes, foreign keys, AUTO_INCREMENT, inline ENUM(...) types and COMMENT clauses, then ALTER TABLE and CREATE INDEX. It reads mysqldump's output as the mysql client would: DELIMITER blocks, comments and /*!... */ version comments. USE and CREATE DATABASE are ignored, so the tables of a one-database dump land in public.

Statements the model cannot hold are skipped, and the import tells you how many: views and materialized views, functions, procedures and triggers, domains, extensions, policies and grants, check and exclusion constraints, the expressions of generated columns, the condition of a partial index (the index is kept), indexes on expressions, PARTITION OF tables, and data statements. FULLTEXT and SPATIAL indexes become plain indexes. Session settings, owners, sequences, DROP statements and transactions are skipped silently.

When the text does not parse: a PostgreSQL dump stops the import at the first syntax error, with its line and column. A MySQL dump skips each statement it cannot read with a warning, and stops only when no table could be read.

What an import creates

  • Tables are placed on a grid. Run Auto-layout to arrange them. An import creates no areas.
  • Schemas. A database starts with one schema, public. Tables without a schema land in it, and an imported schema whose name already exists in the database is reused. In MySQL, the imported database becomes the public schema.
  • Data types are stored in their canonical, lowercase form: character varying(45), timestamp with time zone, numeric(10,2), smallint unsigned.
  • Keys. Composite primary keys and composite foreign keys keep all their columns. Each foreign key becomes a column relationship with its constraint name and its ON DELETE and ON UPDATE actions: one-to-one when its columns are a key of their table, many-to-one otherwise. A foreign key or an index without a name gets the name the database would give it.
  • Enum types become column definitions. A PostgreSQL enum type becomes a definition of the same name. A MySQL inline ENUM(...) becomes a definition named after the first column that uses it (<table>_<column>), shared by every column with the same values. A definition of your organization with the same name and values (in MySQL, the same values) is linked instead; a name your organization already uses for other values gets a _2 suffix and a warning. The columns of that type are linked to the definition. Only the enum types some column uses are imported.
  • New definitions are created in your organization when you import into a database. In a draft, they stay in the draft and are created in your organization when you save.
  • Descriptions come from the database's comments.
  • History. The import is one change in the database's history, with new ids for every object. It is not part of the undo history: to take it back, delete the tables it created.

Limits and privacy

  • The canvas's Import dialog sends what you paste to Architure's server: up to 1 MB per import, and 20 imports per hour from one network address. Past the limit, the dialog says when to try again.
  • The start screen of https://app.architure.dev/new reads a catalog query result in your browser, whatever its size, and sends only a dump to the server (the same 1 MB and 20 per hour).
  • Architure does not keep the text you paste: it keeps the diagram built from it. In a draft, that diagram stays in your browser until you save.

On this page