Skip to content

Tracking: lossless import of an existing Postgres database #242

Open

Description

@cultron

Tracking issue for making apso import → apso generate lossless on an existing Postgres database. This is the onboarding path for any team that already has a database, and it blocks our first customer on a HIPAA business tier.

Why this came up

We're onboarding a healthcare SaaS customer onto Apso. Their app runs on an existing 80-table production Postgres schema, built by hand-written migrations over about seven months. The plan is to move their data layer onto Apso: apso import supabase, then apso generate, then serve the existing database through the generated service.

We ran that end to end locally with CLI 0.50.1, against a copy of the schema loaded with synthetic data. Then we compared the schema the generated service builds against the real one, object by object. Anything that doesn't survive that round trip means the generated service would change or drop production schema the moment it's pointed at the real database.

What we measured

We compared the source schema with the schema the generated service creates (CLI 0.50.1):

Object Source After import and generate Cause
Foreign-key columns patient_id patientId (87 of 88 renamed) #241
created_at / updated_at timestamptz timestamp (about 100 columns) #243
Indexes 176 114 differ: 66 on renamed FKs, 35 partial, 4 expression, 9 template bugs #241, #245, #249, #248
Check constraints 44 0 #246
Column defaults 27 lost, 10 changed (70 more are gen_random_uuid() vs uuid_generate_v4(), same behavior) #247

On top of that, apso schema lint --fix silently changes what unique constraints mean (#244), and the importer has smaller gaps (#250). Separately, the generated TypeScript service starts with 91 known production-dependency vulnerabilities, 29 of them high (apsoai/service-template-ts#47). That needs fixing before Apso is offered as a HIPAA tier.

Done when

Scope note: what belongs in the database

Not everything in a hand-built schema should be carried into .apsorc as-is. Of the 44 check constraints, about 11 are true integrity invariants: date ordering, positive counts, access-grant shape. 25 are status and kind value lists that read better as values and generate API validation. 7 are business rules that belong in application code, because they encode yearly-changing measure codes and an encryption envelope format. So Apso needs a small, explicit checks escape hatch, not a full constraint language. The docs should say which rules belong where.

Activity

  1. added
    enhancement
    on Nov 17, 2026
  2. cultron commented on Nov 24, 2026

    @cultron
    ContributorAuthor

    Status after @apso/cli 0.53.0 (#251), @apso/schema-tools 0.2.3 and service-template-ts v2.1.3: #241, #243, #244, #245, #247, #248 and #249 are closed. Stored generated columns also import now, as a generated field setting (TypeScript only).

    Still open: the check shorthands in #246, composite keys in the API (#250), and a second foreign key on one column, which the importer reports and does not carry.

  3. cultron commented on Nov 25, 2026

    @cultron
    ContributorAuthor

    Shipped in 0.55.0 (#262): a second foreign key on a column survives an import, as the entity setting foreignKeys. The importer writes an entry only when it can state the key exactly (target table imported, key points at the target's primary key, rule is NO ACTION, CASCADE, SET NULL or RESTRICT); any other second key is a line in the import report. Still open under this issue: #246 (check shorthands) and #250 (composite keys).

  4. cultron commented on Nov 25, 2026

    @cultron
    ContributorAuthor

    Shipped in 0.56.0 (#263): a foreign key keeps its ON UPDATE rule, SET DEFAULT, DEFERRABLE and its column's default on import (relationship settings onUpdate, deferrable, joinColumnDefault); a key onto a table whose primary key is a relationship references that column; a key into a table that was not imported, another schema, or a column that is not the target's primary key is a line in the import report with its column kept. Still open under this issue: #246 (check shorthands) and #250 (composite keys).

  5. cultron commented on Nov 25, 2026

    @cultron
    ContributorAuthor

    Status, 2026-11-25 (later):

    • Docs: apsoai/docs#23 is merged. The .apsorc reference, the schema guides and the migrate guide cover every key the import writes, and steps 1 to 4 of the guide were rerun on @apso/cli 0.57.0.
    • Data copy: rerunning the guide on a small second schema showed that apso import data fails on any table with an array column and rounds timestamps to the millisecond. fix: apso import data copies array columns and keeps a timestamp's microseconds #265 fixes both by passing values as the text Postgres prints. It is open and not merged.
    • Found in the same rerun, still open: a bigint or identity id imports as serial; a uuid primary key with no default gains uuid_generate_v4(); an enum type is renamed to <table>_<column>_enum.

    Still open from before: #246 (check shorthands) and #250 (composite keys).

  6. cultron commented on Nov 25, 2026

    @cultron
    ContributorAuthor

    Status, 2026-11-25 (evening): #265 is merged and published as @apso/cli 0.57.1. apso import data now copies a table with an array column and keeps timestamps to the microsecond. The migrate guide is updated (apsoai/docs#24).

    Still open: a bigint or identity id imports as serial, a uuid primary key with no default gains one, an enum type is renamed, #246 (check shorthands) and #250 (composite keys).

  7. cultron commented on Nov 25, 2026

    @cultron
    ContributorAuthor

    Status, 2026-11-25 (night):

    Still open: routes that address a row by a composite key, which need @apso/crud (its routes are fixed at /:id) and a decision on the URL shape, and the check shorthands in #246.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions