caelum0x 261ea5dea7 feat: scribase-migrate — one-command migration from Supabase/Neon/Clerk/Resend onto Scribase
Composes Scribase's own shipped APIs (the `scribase` SDK's imports/migrations/
database/environments resources, plus the GoTrue admin API every self-hosted
Supabase migration tool already uses) rather than reinventing a dump format:

- supabase: wraps the real POST /v1/imports one-call migration (Postgres,
  auth.users with hashes, storage).
- neon: pg_dump schema+data as plain SQL, submitted through POST .../migrations
  (environments.connection() is internal-network-only — verified live — so
  this is the only path that actually reaches a Scribase env from outside);
  auto-generates owner-based RLS so the real migration lint's BLOCK on
  RLS-less public tables is satisfied without ever opening a table to every
  user; branches land in branch_<name> schemas.
- clerk: exports users via the real Backend API, creates them via the
  destination's GoTrue admin API with a one-time password + reset flag
  (Clerk never exposes a portable hash on any plan).
- resend: exports sending domains + broadcasts (as templates) to a portable
  JSON bundle; honest about Scribase having no write endpoint for either yet.

Verified live end-to-end against a real local Supabase-shaped Postgres
(Docker, GoTrue-shaped auth.users with a real bcrypt hash) and a real
Scribase project (ereboslab/scribase-migrate-verify-internal): schema+RLS
applied with 0 lint blocks, data row counts matched via a real HTTP query
(2/2 profiles, 3/3 notes), and a real password-grant login returned a real
access_token for the migrated user. Full artifacts in
test-fixtures/verification-run/.

docs/migrate-page.md is a ready-to-paste scribase.com/migrate page.
2026-11-17 14:54:36 +03:00

42 lines
1.8 KiB
SQL

create schema if not exists auth;
create table auth.users (
id uuid primary key,
instance_id uuid,
aud varchar(255),
role varchar(255),
email varchar(255) unique,
encrypted_password varchar(255),
email_confirmed_at timestamptz,
raw_app_meta_data jsonb default '{}',
raw_user_meta_data jsonb default '{}',
created_at timestamptz default now(),
updated_at timestamptz default now()
);
insert into auth.users (id, instance_id, aud, role, email, encrypted_password, email_confirmed_at, raw_app_meta_data, raw_user_meta_data)
values
('11111111-1111-1111-1111-111111111111', '00000000-0000-0000-0000-000000000000', 'authenticated', 'authenticated', 'migrate-verify@example.com', '$2a$10$77oozt4JNQI/24.iqiaWNujIJR76biCpWYqCG8V3bA6fKMSKH0dJG', now(), '{"provider":"email"}', '{"migrated_from":"source"}'),
('22222222-2222-2222-2222-222222222222', '00000000-0000-0000-0000-000000000000', 'authenticated', 'authenticated', 'second-user@example.com', '$2a$10$77oozt4JNQI/24.iqiaWNujIJR76biCpWYqCG8V3bA6fKMSKH0dJG', now(), '{"provider":"email"}', '{}');
create table public.profiles (
id uuid primary key references auth.users(id),
display_name text not null,
plan text default 'free',
created_at timestamptz default now()
);
insert into public.profiles (id, display_name, plan) values
('11111111-1111-1111-1111-111111111111', 'Migrate Verify', 'pro'),
('22222222-2222-2222-2222-222222222222', 'Second User', 'free');
create table public.notes (
id serial primary key,
profile_id uuid references public.profiles(id),
body text not null
);
insert into public.notes (profile_id, body) values
('11111111-1111-1111-1111-111111111111', 'first note'),
('11111111-1111-1111-1111-111111111111', 'second note'),
('22222222-2222-2222-2222-222222222222', 'third note');