@authhero/kysely-adapter 11.8.11 → 11.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kysely-adapter.cjs +1 -1
- package/dist/kysely-adapter.d.ts +1 -0
- package/dist/kysely-adapter.mjs +22 -9
- package/dist/types/migrate/migrations/2026-06-27T12:00:00_tenant_database_version.d.ts +11 -0
- package/dist/types/migrate/migrations/index.d.ts +2 -0
- package/dist/types/src/db.d.ts +1 -0
- package/dist/types/src/tenants/list.d.ts +2 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/kysely-adapter.cjs
CHANGED
|
@@ -181,4 +181,4 @@ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{val
|
|
|
181
181
|
UPDATE clients
|
|
182
182
|
SET client_metadata = json_remove(client_metadata, '$.disable_sign_ups')
|
|
183
183
|
WHERE json_extract(client_metadata, '$.disable_sign_ups') IS NOT NULL
|
|
184
|
-
`.execute(e))}async function _h(e){await e.schema.alterTable(`clients`).dropColumn(`hide_sign_up_disabled_error`).execute(),await e.schema.alterTable(`clients`).dropColumn(`disable_sign_ups`).execute()}var vh=t({down:()=>xh,up:()=>bh});async function yh(e){try{return await i.sql`SELECT VERSION()`.execute(e),`mysql`}catch{return`sqlite`}}async function bh(e){await yh(e);let t=await e.selectFrom(`clients`).select([`tenant_id`,`connections`]).where(`disable_sign_ups`,`=`,1).execute(),n=new Map;for(let e of t){let t=[];try{t=JSON.parse(e.connections||`[]`)}catch{t=[]}if(!Array.isArray(t)||t.length===0)continue;let r=n.get(e.tenant_id);r||(r=new Set,n.set(e.tenant_id,r));for(let e of t)r.add(e)}for(let[t,r]of n){let n=await e.selectFrom(`connections`).select([`id`,`options`]).where(`tenant_id`,`=`,t).where(`id`,`in`,[...r]).execute();for(let r of n){let n={};try{n=r.options?JSON.parse(r.options):{}}catch{n={}}n.disable_signup!==!0&&(n.disable_signup=!0,await e.updateTable(`connections`).set({options:JSON.stringify(n)}).where(`tenant_id`,`=`,t).where(`id`,`=`,r.id).execute())}}await e.schema.alterTable(`clients`).dropColumn(`disable_sign_ups`).execute()}async function xh(e){await e.schema.alterTable(`clients`).addColumn(`disable_sign_ups`,`integer`,e=>e.notNull().defaultTo(0)).execute()}var Sh=t({down:()=>wh,up:()=>Ch});async function Ch(e){await e.schema.alterTable(`actions`).addColumn(`is_system`,`integer`,e=>e.notNull().defaultTo(0)).execute(),await e.schema.alterTable(`actions`).addColumn(`inherit`,`integer`,e=>e.notNull().defaultTo(0)).execute()}async function wh(e){await e.schema.alterTable(`actions`).dropColumn(`inherit`).execute(),await e.schema.alterTable(`actions`).dropColumn(`is_system`).execute()}var Th=t({down:()=>kh,up:()=>Oh}),Eh=[`token_endpoint`,`userinfo_endpoint`,`client_id`,`client_secret`];function Dh(e){if(!e)return{};try{let t=JSON.parse(e);return t&&typeof t==`object`?t:{}}catch{return{}}}async function Oh(e){let t=await e.selectFrom(`connections`).select([`id`,`tenant_id`,`options`]).where(`strategy`,`=`,`auth0`).execute(),n=new Map;for(let e of t){let t=n.get(e.tenant_id)??[];t.push(e),n.set(e.tenant_id,t)}let r=[...n.entries()].filter(([,e])=>e.length!==1);if(r.length>0){let e=r.map(([e,t])=>`${e} (${t.length} rows: ${t.map(e=>e.id).join(`, `)})`).join(`; `);throw Error(`[collapse_auth0_source] cannot proceed: the following tenants have more than one strategy="auth0" connection — resolve manually before re-running the migration: ${e}`)}for(let[t,r]of n){let n=r[0],i=await e.selectFrom(`connections`).select([`id`,`name`,`options`]).where(`tenant_id`,`=`,t).where(`strategy`,`=`,`Username-Password-Authentication`).execute();if(i.length===0){console.warn(`[collapse_auth0_source] tenant=${t}: auth0 connection ${n.id} has no DB connection to merge into; deleting it`),await e.deleteFrom(`connections`).where(`tenant_id`,`=`,t).where(`id`,`=`,n.id).execute();continue}if(i.length>1){console.warn(`[collapse_auth0_source] tenant=${t}: ${i.length} DB connections found; skipping merge — resolve manually before next deploy`);continue}let a=Dh(n.options),o={};for(let e of Eh)typeof a[e]==`string`&&(o[e]=a[e]);let s=i[0],c=Dh(s.options);c.configuration={...c.configuration&&typeof c.configuration==`object`?c.configuration:{},...o},await e.updateTable(`connections`).set({options:JSON.stringify(c)}).where(`tenant_id`,`=`,t).where(`id`,`=`,s.id).execute(),await e.deleteFrom(`connections`).where(`tenant_id`,`=`,t).where(`id`,`=`,n.id).execute()}}async function kh(){}var Ah=t({down:()=>Mh,up:()=>jh});async function jh(e){await e.schema.createTable(`migration_sources`).addColumn(`id`,`varchar(64)`,e=>e.primaryKey()).addColumn(`tenant_id`,`varchar(191)`,e=>e.notNull()).addColumn(`name`,`varchar(255)`,e=>e.notNull()).addColumn(`provider`,`varchar(32)`,e=>e.notNull()).addColumn(`connection`,`varchar(255)`,e=>e.notNull()).addColumn(`enabled`,`boolean`,e=>e.notNull()).addColumn(`credentials`,`text`,e=>e.notNull()).addColumn(`created_at`,`varchar(35)`,e=>e.notNull()).addColumn(`updated_at`,`varchar(35)`,e=>e.notNull()).execute(),await e.schema.createIndex(`idx_migration_sources_tenant_id`).on(`migration_sources`).columns([`tenant_id`]).execute()}async function Mh(e){await e.schema.dropTable(`migration_sources`).execute()}var Nh=t({down:()=>Fh,up:()=>Ph});async function Ph(e){await e.schema.createTable(`proxy_routes`).addColumn(`id`,`varchar(64)`,e=>e.notNull().primaryKey()).addColumn(`tenant_id`,`varchar(255)`,e=>e.notNull()).addColumn(`custom_domain_id`,`varchar(256)`,e=>e.notNull()).addColumn(`priority`,`integer`,e=>e.notNull().defaultTo(100)).addColumn(`path_pattern`,`varchar(512)`,e=>e.notNull()).addColumn(`upstream_type`,`varchar(32)`,e=>e.notNull()).addColumn(`upstream_url`,`varchar(2048)`,e=>e.notNull()).addColumn(`preserve_host`,`integer`,e=>e.notNull().defaultTo(0)).addColumn(`middleware`,`varchar(8192)`,e=>e.notNull().defaultTo(`[]`)).addColumn(`created_at`,`varchar(35)`,e=>e.notNull()).addColumn(`updated_at`,`varchar(35)`,e=>e.notNull()).execute(),await e.schema.createIndex(`proxy_routes_tenant_id_idx`).on(`proxy_routes`).column(`tenant_id`).execute(),await e.schema.createIndex(`proxy_routes_custom_domain_id_idx`).on(`proxy_routes`).column(`custom_domain_id`).execute()}async function Fh(e){await e.schema.dropTable(`proxy_routes`).execute()}var Ih=t({down:()=>Bh,up:()=>zh});function Lh(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{let{type:t,...n}=e;return{type:t,options:n}}):[]}catch{return[]}}function Rh(e){let t=Lh(e.middleware),n={type:e.upstream_type===`authhero`?`http`:e.upstream_type,options:{upstream_url:e.upstream_url,preserve_host:e.preserve_host!==0}};return[...t,n]}async function zh(e){await e.schema.alterTable(`proxy_routes`).addColumn(`match`,`varchar(2048)`,e=>e.notNull().defaultTo(`{"path":"/*"}`)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`handlers`,`text`,e=>e.notNull().defaultTo(`[]`)).execute();let t=await e.selectFrom(`proxy_routes`).select([`id`,`path_pattern`,`upstream_type`,`upstream_url`,`preserve_host`,`middleware`]).execute();for(let n of t){let t={path:n.path_pattern||`/*`},r=Rh(n);await e.updateTable(`proxy_routes`).set({match:JSON.stringify(t),handlers:JSON.stringify(r)}).where(`id`,`=`,n.id).execute()}await e.schema.alterTable(`proxy_routes`).dropColumn(`path_pattern`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`upstream_type`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`upstream_url`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`preserve_host`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`middleware`).execute()}async function Bh(e){await e.schema.alterTable(`proxy_routes`).addColumn(`path_pattern`,`varchar(512)`,e=>e.notNull().defaultTo(`/*`)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`upstream_type`,`varchar(32)`,e=>e.notNull().defaultTo(`http`)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`upstream_url`,`varchar(2048)`,e=>e.notNull().defaultTo(``)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`preserve_host`,`integer`,e=>e.notNull().defaultTo(0)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`middleware`,`varchar(8192)`,e=>e.notNull().defaultTo(`[]`)).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`match`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`handlers`).execute()}var Vh=t({down:()=>Wh,up:()=>Uh});async function Hh(e){try{return await i.sql`SELECT VERSION()`.execute(e),`mysql`}catch{return`sqlite`}}async function Uh(e){await Hh(e)===`mysql`&&(q(`Widening user_permissions.resource_server_identifier from varchar(21) to varchar(100)...`),await e.schema.alterTable(`user_permissions`).modifyColumn(`resource_server_identifier`,`varchar(100)`,e=>e.notNull()).execute())}async function Wh(e){await Hh(e)===`mysql`&&await e.schema.alterTable(`user_permissions`).modifyColumn(`resource_server_identifier`,`varchar(21)`,e=>e.notNull()).execute()}var Gh=t({down:()=>qh,up:()=>Kh});async function Kh(e){await e.schema.createTable(`grants`).addColumn(`id`,`varchar(21)`,e=>e.primaryKey()).addColumn(`tenant_id`,`varchar(255)`,e=>e.references(`tenants.id`).onDelete(`cascade`).notNull()).addColumn(`user_id`,`varchar(255)`,e=>e.notNull()).addForeignKeyConstraint(`grants_user_id_constraint`,[`user_id`,`tenant_id`],`users`,[`user_id`,`tenant_id`],e=>e.onDelete(`cascade`)).addColumn(`client_id`,`varchar(100)`,e=>e.notNull()).addColumn(`audience`,`varchar(100)`,e=>e.notNull().defaultTo(``)).addColumn(`scope`,`text`,e=>e.notNull().defaultTo(`[]`)).addColumn(`created_at`,`varchar(35)`,e=>e.notNull()).addColumn(`updated_at`,`varchar(35)`,e=>e.notNull()).execute(),await e.schema.createIndex(`grants_natural_key_idx`).on(`grants`).columns([`tenant_id`,`user_id`,`client_id`,`audience`]).unique().execute(),await e.schema.createIndex(`grants_tenant_user_idx`).on(`grants`).columns([`tenant_id`,`user_id`]).execute()}async function qh(e){await e.schema.dropTable(`grants`).execute()}var Jh=t({down:()=>Xh,up:()=>Yh});async function Yh(e){await i.sql`UPDATE clients SET is_first_party = 1 WHERE is_first_party = 0`.execute(e)}async function Xh(e){}var Zh=t({down:()=>$h,up:()=>Qh});async function Qh(e){await e.schema.alterTable(`tenants`).addColumn(`deployment_type`,`varchar(16)`,e=>e.notNull().defaultTo(`shared`)).execute(),await e.schema.alterTable(`tenants`).addColumn(`provisioning_state`,`varchar(16)`,e=>e.notNull().defaultTo(`ready`)).execute(),await e.schema.alterTable(`tenants`).addColumn(`provisioning_error`,`varchar(2048)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`provisioning_state_changed_at`,`varchar(35)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`bundle_configuration`,`varchar(64)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`worker_version`,`varchar(64)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`worker_script_name`,`varchar(255)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`storage_kind`,`varchar(32)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`d1_database_id`,`varchar(64)`).execute()}async function $h(e){await e.schema.alterTable(`tenants`).dropColumn(`d1_database_id`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`storage_kind`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`worker_script_name`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`worker_version`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`bundle_configuration`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`provisioning_state_changed_at`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`provisioning_error`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`provisioning_state`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`deployment_type`).execute()}var eg={m1_init:Aa,m2_magicLink:Na,m3_updateAt:Ia,m4_logTable:za,m5_userProfile:Ha,m6_sessions:Ga,m7_passwords:Ja,m8_logsTableNewFields:Za,m9_passwordTableNewField:eo,n01_codesTable:ro,n11_universalLoginSession:oo,n12_userFields:lo,n13_userEmailIndex:po,n14_profileDataField:go,n15_userEmailIndex:yo,n16_userLocale:So,n17_signingKeys:To,n18_logsFields:Oo,n19_connectionsUserinfo:jo,n20_missingFields:Po,n21_sessionDeletedAt:Lo,n22_dropLogsFields:Bo,n23_dropUsersFields:Uo,n24_logsIndexes:Ko,n25_logDescMaxLength:Yo,n26_logsTableExtraFields:Qo,n27_usersTableNameIndex:ts,n28_usersEmailConstrain:is,n29_increaseOtpStateLength:ss,n30_increaseTicketStateLength:us,n31_branding:ps,n32_indexesAndNotNull:gs,n33_vendorIdInUniversalLoginSession:ys,n34_auth0ClientInUniversalLoginSession:Ss,n35_increaseUniversalSessionStateLength:Ts,n36_authenticationCodes:Os,n37_disableSignUps:js,n38_otpIpAddress:Ps,n39_increaseUserAgentLength:Ls,n40_userId:Bs,n41_hooks:Us,n42_userIdIndexes:Ks,n43_userIdIndexes:Ys,n44_codes:Qs,n45_hookProperties:tc,n46_loginAuth0Client:ic,n47_loginAuth0Client:sc,n48_saml:uc,n49_removeFields:pc,n50_authParamsNonce:gc,n51_connectionid:yc,n52_cert:Sc,n53_codes_primary_key:Tc,n54_cleanup_tables:Oc,n55_logs_index:jc,n56_application_fields:Pc,n57_prompt_settings:Lc,n58_connection_client_id:Bc,n59_connection_options:Uc,n60_users_metadata:Kc,n61_userLocales:Yc,n62_prompt:Qc,n63_connection_cleanup:tl,n64_act_as:il,n65_code_verifier:sl,n66_email_providers:ul,n67_drop_tickets:pl,n68_login_useragents:gl,n70_refresh_tokens:yl,n71_session_new_fields:Sl,n72_session_primary_key:Tl,n73_drop_sessions:Ol,n74_custom_domains:jl,n75_organizations:Pl,n76_authorization_url_length:Ll,n77_drop_sessions:Bl,n78_login_sessions:Ul,n79_drop_sessions_2:Kl,n80_recreate_custom_domains:Yl,n81_phone:Ql,n82_forms:tu,n83_addFormsIdToHooks:iu,n84_login_completed:su,n85_add_login_session_id_to_sessions:uu,n86_index_sessions_login_session_id:pu,n87_code_challenge:gu,n88_add_redirect_uri_to_codes:yu,n89_add_nonce_and_state_to_codes:Su,n90_themes:Tu,n91_resource_servers_rules_permissions:Ou,n92_role_permissions:ju,n93_add_permissions_to_roles:Pu,n94_keys_connection_and_extend_columns:Lu,n95_create_organizations_table:Bu,n96_create_user_organizations_table:Uu,n97_add_organization_to_user_permissions_and_roles:Ku,n98_clients:Yu,n99_update_client_foreign_keys:ed,o001_client_grants:cd,o002_drop_applications:dd,o003_phone_number_index:md,o004_login_sessions_id_index:_d,o005_connections_tenant_index:bd,o006_remove_redundant_user_organizations_tenant_index:Cd,o007_tenant_settings:Ed,o008_merge_tenant_settings_into_tenants:kd,o009_create_invites_table:Md,o010_add_log_id_to_logs:Fd,o011_add_location_info_to_logs:Rd,o012_add_password_history:Vd,o013_connection_display_name:Wd,o014_client_connections:qd,o015_flows:Xd,o016_add_is_system_column:$d,o017_connections_composite_key:nf,o018_login_session_state:of,o019_roles_resource_servers_metadata:lf,o020_session_add_timestamp_columns:ff,o021_session_cleanup_and_ulid:gf,o022_oidc_profile_claims:bf,o023_preferred_username:Cf,o024_user_address:Ef,o025_authparams_max_age:kf,o026_auth0_conformant:Mf,o027_universal_login_templates:Ff,o028_custom_text:Rf,o029_guardian_mfa:Vf,o030_add_template_id_to_hooks:Wf,o031_hooks_cleanup:Xf,o032_unique_username_provider:tp,o033_add_login_id_to_refresh_tokens:ip,o034_refresh_tokens_replace_session_id_with_login_id:sp,o035_idle_expires_at_ts_indexes:dp,o036_add_connection_to_login_sessions:mp,o037_mfa_enrollments:_p,o038_add_otp_to_codes:bp,o039_rename_mfa_enrollments_to_authentication_methods:Cp,o040_create_outbox_events:Ep,o041_add_outbox_claim_columns:kp,o042_add_outbox_claim_index:Mp,o043_add_code_hooks:Fp,o044_create_actions:Rp,o045_outbox_dead_letter:Vp,o046_user_registration_completed_at:Wp,o047_outbox_dead_lettered_tenant_index:qp,o048_add_auth_strategy_to_login_sessions:Xp,o049_login_sessions_auth_params:$p,o050_login_sessions_auth_params_backfill:rm,o051_relax_login_sessions_authparams:lm,o052_drop_login_sessions_hoisted_authparams:hm,o053_refresh_tokens_revoked_at:Cm,o054_client_registration_tokens:Em,o055_planetscale_redundant_indexes_cleanup:km,o056_client_user_linking_mode:Fm,o057_hooks_metadata:Rm,o058_refresh_tokens_rotation:Vm,o059_organization_connections:Wm,o060_log_streams:qm,o061_tenants_attack_protection:Xm,o062_tenants_default_client_id:$m,o063_email_templates:nh,o064_create_action_versions:ah,o065_branding_dark_mode:ch,o066_create_action_executions:dh,o067_client_disable_sign_ups:mh,o068_move_disable_signup_to_connection:vh,o069_actions_is_system_inherit:Sh,o070_collapse_auth0_source_into_db_connection:Th,o071_migration_sources:Ah,o072_proxy_routes:Nh,o073_proxy_routes_v2:Ih,o074_widen_user_permissions_resource_server_identifier:Vh,o075_create_grants:Gh,o076_default_first_party_true:Jh,o077_tenant_deployment_fields:Zh};async function tg(e,t=!1){$u(t),t&&console.log(`migrating...`);let{error:n,results:r}=await new Oa({db:e,provider:new ka(eg)}).migrateToLatest();if(r?.forEach(e=>{e.status===`Success`?t&&console.log(`migration "${e.migrationName}" was executed successfully`):e.status===`Error`&&console.error(`failed to execute migration "${e.migrationName}"`)}),n)throw console.error(`failed to migrate`),console.error(n),n}async function ng(e,t=!1){$u(t),t&&console.log(`migrating...`);let{error:n,results:r}=await new Oa({db:e,provider:new ka(eg)}).migrateDown();if(r?.forEach(e=>{e.status===`Success`?t&&console.log(`migration "${e.migrationName}" was reverted successfully`):e.status===`Error`&&console.error(`failed to execute migration "${e.migrationName}"`)}),n)throw console.error(`failed to migrate`),console.error(n),n}function rg(e,t={useTransactions:!0}){let n={actions:oe(e),actionExecutions:ue(e),actionVersions:pe(e),branding:mn(e),clients:kt(e),clientConnections:Ft(e),clientGrants:Vt(e),clientRegistrationTokens:$t(e),codes:mt(e),connections:St(e),emailProviders:tr(e),emailTemplates:cr(e),customDomains:dn(e),flows:Me(e),forms:Tr(e),hookCode:kn(e),hooks:wn(e),invites:Ci(e),keys:rn(e),loginSessions:Kn(e),logs:Xe(e),logStreams:aa(e),migrationSources:oa(e),authenticationMethods:qi(e),passwords:st(e),promptSettings:Xn(e),proxyRoutes:z(e),refreshTokens:_r(e),resourceServers:jr(e),rolePermissions:Vr(e),grants:qr(e),userPermissions:Qr(e),userRoles:ri(e),roles:Lr(e),sessions:nt(e),sessionCleanup:yr(e),tenants:He(e),themes:Pn(e),universalLoginTemplates:vn(e),customText:Bi(e),users:we(e),organizations:li(e),organizationConnections:ui(e),userOrganizations:_i(e),stats:Oi(e),analytics:zi(e),outbox:ia(e),async transaction(r){return t.useTransactions===!1?r(n):e.transaction().execute(async e=>r(rg(e,{...t,useTransactions:!1})))}};return n}exports.createProxyDataAdapter=ua,exports.createProxyRoutesAdapter=z,exports.default=rg,exports.migrateDown=ng,exports.migrateToLatest=tg;
|
|
184
|
+
`.execute(e))}async function _h(e){await e.schema.alterTable(`clients`).dropColumn(`hide_sign_up_disabled_error`).execute(),await e.schema.alterTable(`clients`).dropColumn(`disable_sign_ups`).execute()}var vh=t({down:()=>xh,up:()=>bh});async function yh(e){try{return await i.sql`SELECT VERSION()`.execute(e),`mysql`}catch{return`sqlite`}}async function bh(e){await yh(e);let t=await e.selectFrom(`clients`).select([`tenant_id`,`connections`]).where(`disable_sign_ups`,`=`,1).execute(),n=new Map;for(let e of t){let t=[];try{t=JSON.parse(e.connections||`[]`)}catch{t=[]}if(!Array.isArray(t)||t.length===0)continue;let r=n.get(e.tenant_id);r||(r=new Set,n.set(e.tenant_id,r));for(let e of t)r.add(e)}for(let[t,r]of n){let n=await e.selectFrom(`connections`).select([`id`,`options`]).where(`tenant_id`,`=`,t).where(`id`,`in`,[...r]).execute();for(let r of n){let n={};try{n=r.options?JSON.parse(r.options):{}}catch{n={}}n.disable_signup!==!0&&(n.disable_signup=!0,await e.updateTable(`connections`).set({options:JSON.stringify(n)}).where(`tenant_id`,`=`,t).where(`id`,`=`,r.id).execute())}}await e.schema.alterTable(`clients`).dropColumn(`disable_sign_ups`).execute()}async function xh(e){await e.schema.alterTable(`clients`).addColumn(`disable_sign_ups`,`integer`,e=>e.notNull().defaultTo(0)).execute()}var Sh=t({down:()=>wh,up:()=>Ch});async function Ch(e){await e.schema.alterTable(`actions`).addColumn(`is_system`,`integer`,e=>e.notNull().defaultTo(0)).execute(),await e.schema.alterTable(`actions`).addColumn(`inherit`,`integer`,e=>e.notNull().defaultTo(0)).execute()}async function wh(e){await e.schema.alterTable(`actions`).dropColumn(`inherit`).execute(),await e.schema.alterTable(`actions`).dropColumn(`is_system`).execute()}var Th=t({down:()=>kh,up:()=>Oh}),Eh=[`token_endpoint`,`userinfo_endpoint`,`client_id`,`client_secret`];function Dh(e){if(!e)return{};try{let t=JSON.parse(e);return t&&typeof t==`object`?t:{}}catch{return{}}}async function Oh(e){let t=await e.selectFrom(`connections`).select([`id`,`tenant_id`,`options`]).where(`strategy`,`=`,`auth0`).execute(),n=new Map;for(let e of t){let t=n.get(e.tenant_id)??[];t.push(e),n.set(e.tenant_id,t)}let r=[...n.entries()].filter(([,e])=>e.length!==1);if(r.length>0){let e=r.map(([e,t])=>`${e} (${t.length} rows: ${t.map(e=>e.id).join(`, `)})`).join(`; `);throw Error(`[collapse_auth0_source] cannot proceed: the following tenants have more than one strategy="auth0" connection — resolve manually before re-running the migration: ${e}`)}for(let[t,r]of n){let n=r[0],i=await e.selectFrom(`connections`).select([`id`,`name`,`options`]).where(`tenant_id`,`=`,t).where(`strategy`,`=`,`Username-Password-Authentication`).execute();if(i.length===0){console.warn(`[collapse_auth0_source] tenant=${t}: auth0 connection ${n.id} has no DB connection to merge into; deleting it`),await e.deleteFrom(`connections`).where(`tenant_id`,`=`,t).where(`id`,`=`,n.id).execute();continue}if(i.length>1){console.warn(`[collapse_auth0_source] tenant=${t}: ${i.length} DB connections found; skipping merge — resolve manually before next deploy`);continue}let a=Dh(n.options),o={};for(let e of Eh)typeof a[e]==`string`&&(o[e]=a[e]);let s=i[0],c=Dh(s.options);c.configuration={...c.configuration&&typeof c.configuration==`object`?c.configuration:{},...o},await e.updateTable(`connections`).set({options:JSON.stringify(c)}).where(`tenant_id`,`=`,t).where(`id`,`=`,s.id).execute(),await e.deleteFrom(`connections`).where(`tenant_id`,`=`,t).where(`id`,`=`,n.id).execute()}}async function kh(){}var Ah=t({down:()=>Mh,up:()=>jh});async function jh(e){await e.schema.createTable(`migration_sources`).addColumn(`id`,`varchar(64)`,e=>e.primaryKey()).addColumn(`tenant_id`,`varchar(191)`,e=>e.notNull()).addColumn(`name`,`varchar(255)`,e=>e.notNull()).addColumn(`provider`,`varchar(32)`,e=>e.notNull()).addColumn(`connection`,`varchar(255)`,e=>e.notNull()).addColumn(`enabled`,`boolean`,e=>e.notNull()).addColumn(`credentials`,`text`,e=>e.notNull()).addColumn(`created_at`,`varchar(35)`,e=>e.notNull()).addColumn(`updated_at`,`varchar(35)`,e=>e.notNull()).execute(),await e.schema.createIndex(`idx_migration_sources_tenant_id`).on(`migration_sources`).columns([`tenant_id`]).execute()}async function Mh(e){await e.schema.dropTable(`migration_sources`).execute()}var Nh=t({down:()=>Fh,up:()=>Ph});async function Ph(e){await e.schema.createTable(`proxy_routes`).addColumn(`id`,`varchar(64)`,e=>e.notNull().primaryKey()).addColumn(`tenant_id`,`varchar(255)`,e=>e.notNull()).addColumn(`custom_domain_id`,`varchar(256)`,e=>e.notNull()).addColumn(`priority`,`integer`,e=>e.notNull().defaultTo(100)).addColumn(`path_pattern`,`varchar(512)`,e=>e.notNull()).addColumn(`upstream_type`,`varchar(32)`,e=>e.notNull()).addColumn(`upstream_url`,`varchar(2048)`,e=>e.notNull()).addColumn(`preserve_host`,`integer`,e=>e.notNull().defaultTo(0)).addColumn(`middleware`,`varchar(8192)`,e=>e.notNull().defaultTo(`[]`)).addColumn(`created_at`,`varchar(35)`,e=>e.notNull()).addColumn(`updated_at`,`varchar(35)`,e=>e.notNull()).execute(),await e.schema.createIndex(`proxy_routes_tenant_id_idx`).on(`proxy_routes`).column(`tenant_id`).execute(),await e.schema.createIndex(`proxy_routes_custom_domain_id_idx`).on(`proxy_routes`).column(`custom_domain_id`).execute()}async function Fh(e){await e.schema.dropTable(`proxy_routes`).execute()}var Ih=t({down:()=>Bh,up:()=>zh});function Lh(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{let{type:t,...n}=e;return{type:t,options:n}}):[]}catch{return[]}}function Rh(e){let t=Lh(e.middleware),n={type:e.upstream_type===`authhero`?`http`:e.upstream_type,options:{upstream_url:e.upstream_url,preserve_host:e.preserve_host!==0}};return[...t,n]}async function zh(e){await e.schema.alterTable(`proxy_routes`).addColumn(`match`,`varchar(2048)`,e=>e.notNull().defaultTo(`{"path":"/*"}`)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`handlers`,`text`,e=>e.notNull().defaultTo(`[]`)).execute();let t=await e.selectFrom(`proxy_routes`).select([`id`,`path_pattern`,`upstream_type`,`upstream_url`,`preserve_host`,`middleware`]).execute();for(let n of t){let t={path:n.path_pattern||`/*`},r=Rh(n);await e.updateTable(`proxy_routes`).set({match:JSON.stringify(t),handlers:JSON.stringify(r)}).where(`id`,`=`,n.id).execute()}await e.schema.alterTable(`proxy_routes`).dropColumn(`path_pattern`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`upstream_type`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`upstream_url`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`preserve_host`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`middleware`).execute()}async function Bh(e){await e.schema.alterTable(`proxy_routes`).addColumn(`path_pattern`,`varchar(512)`,e=>e.notNull().defaultTo(`/*`)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`upstream_type`,`varchar(32)`,e=>e.notNull().defaultTo(`http`)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`upstream_url`,`varchar(2048)`,e=>e.notNull().defaultTo(``)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`preserve_host`,`integer`,e=>e.notNull().defaultTo(0)).execute(),await e.schema.alterTable(`proxy_routes`).addColumn(`middleware`,`varchar(8192)`,e=>e.notNull().defaultTo(`[]`)).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`match`).execute(),await e.schema.alterTable(`proxy_routes`).dropColumn(`handlers`).execute()}var Vh=t({down:()=>Wh,up:()=>Uh});async function Hh(e){try{return await i.sql`SELECT VERSION()`.execute(e),`mysql`}catch{return`sqlite`}}async function Uh(e){await Hh(e)===`mysql`&&(q(`Widening user_permissions.resource_server_identifier from varchar(21) to varchar(100)...`),await e.schema.alterTable(`user_permissions`).modifyColumn(`resource_server_identifier`,`varchar(100)`,e=>e.notNull()).execute())}async function Wh(e){await Hh(e)===`mysql`&&await e.schema.alterTable(`user_permissions`).modifyColumn(`resource_server_identifier`,`varchar(21)`,e=>e.notNull()).execute()}var Gh=t({down:()=>qh,up:()=>Kh});async function Kh(e){await e.schema.createTable(`grants`).addColumn(`id`,`varchar(21)`,e=>e.primaryKey()).addColumn(`tenant_id`,`varchar(255)`,e=>e.references(`tenants.id`).onDelete(`cascade`).notNull()).addColumn(`user_id`,`varchar(255)`,e=>e.notNull()).addForeignKeyConstraint(`grants_user_id_constraint`,[`user_id`,`tenant_id`],`users`,[`user_id`,`tenant_id`],e=>e.onDelete(`cascade`)).addColumn(`client_id`,`varchar(100)`,e=>e.notNull()).addColumn(`audience`,`varchar(100)`,e=>e.notNull().defaultTo(``)).addColumn(`scope`,`text`,e=>e.notNull().defaultTo(`[]`)).addColumn(`created_at`,`varchar(35)`,e=>e.notNull()).addColumn(`updated_at`,`varchar(35)`,e=>e.notNull()).execute(),await e.schema.createIndex(`grants_natural_key_idx`).on(`grants`).columns([`tenant_id`,`user_id`,`client_id`,`audience`]).unique().execute(),await e.schema.createIndex(`grants_tenant_user_idx`).on(`grants`).columns([`tenant_id`,`user_id`]).execute()}async function qh(e){await e.schema.dropTable(`grants`).execute()}var Jh=t({down:()=>Xh,up:()=>Yh});async function Yh(e){await i.sql`UPDATE clients SET is_first_party = 1 WHERE is_first_party = 0`.execute(e)}async function Xh(e){}var Zh=t({down:()=>$h,up:()=>Qh});async function Qh(e){await e.schema.alterTable(`tenants`).addColumn(`deployment_type`,`varchar(16)`,e=>e.notNull().defaultTo(`shared`)).execute(),await e.schema.alterTable(`tenants`).addColumn(`provisioning_state`,`varchar(16)`,e=>e.notNull().defaultTo(`ready`)).execute(),await e.schema.alterTable(`tenants`).addColumn(`provisioning_error`,`varchar(2048)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`provisioning_state_changed_at`,`varchar(35)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`bundle_configuration`,`varchar(64)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`worker_version`,`varchar(64)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`worker_script_name`,`varchar(255)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`storage_kind`,`varchar(32)`).execute(),await e.schema.alterTable(`tenants`).addColumn(`d1_database_id`,`varchar(64)`).execute()}async function $h(e){await e.schema.alterTable(`tenants`).dropColumn(`d1_database_id`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`storage_kind`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`worker_script_name`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`worker_version`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`bundle_configuration`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`provisioning_state_changed_at`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`provisioning_error`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`provisioning_state`).execute(),await e.schema.alterTable(`tenants`).dropColumn(`deployment_type`).execute()}var eg=t({down:()=>ng,up:()=>tg});async function tg(e){await e.schema.alterTable(`tenants`).addColumn(`database_version`,`varchar(64)`).execute()}async function ng(e){await e.schema.alterTable(`tenants`).dropColumn(`database_version`).execute()}var rg={m1_init:Aa,m2_magicLink:Na,m3_updateAt:Ia,m4_logTable:za,m5_userProfile:Ha,m6_sessions:Ga,m7_passwords:Ja,m8_logsTableNewFields:Za,m9_passwordTableNewField:eo,n01_codesTable:ro,n11_universalLoginSession:oo,n12_userFields:lo,n13_userEmailIndex:po,n14_profileDataField:go,n15_userEmailIndex:yo,n16_userLocale:So,n17_signingKeys:To,n18_logsFields:Oo,n19_connectionsUserinfo:jo,n20_missingFields:Po,n21_sessionDeletedAt:Lo,n22_dropLogsFields:Bo,n23_dropUsersFields:Uo,n24_logsIndexes:Ko,n25_logDescMaxLength:Yo,n26_logsTableExtraFields:Qo,n27_usersTableNameIndex:ts,n28_usersEmailConstrain:is,n29_increaseOtpStateLength:ss,n30_increaseTicketStateLength:us,n31_branding:ps,n32_indexesAndNotNull:gs,n33_vendorIdInUniversalLoginSession:ys,n34_auth0ClientInUniversalLoginSession:Ss,n35_increaseUniversalSessionStateLength:Ts,n36_authenticationCodes:Os,n37_disableSignUps:js,n38_otpIpAddress:Ps,n39_increaseUserAgentLength:Ls,n40_userId:Bs,n41_hooks:Us,n42_userIdIndexes:Ks,n43_userIdIndexes:Ys,n44_codes:Qs,n45_hookProperties:tc,n46_loginAuth0Client:ic,n47_loginAuth0Client:sc,n48_saml:uc,n49_removeFields:pc,n50_authParamsNonce:gc,n51_connectionid:yc,n52_cert:Sc,n53_codes_primary_key:Tc,n54_cleanup_tables:Oc,n55_logs_index:jc,n56_application_fields:Pc,n57_prompt_settings:Lc,n58_connection_client_id:Bc,n59_connection_options:Uc,n60_users_metadata:Kc,n61_userLocales:Yc,n62_prompt:Qc,n63_connection_cleanup:tl,n64_act_as:il,n65_code_verifier:sl,n66_email_providers:ul,n67_drop_tickets:pl,n68_login_useragents:gl,n70_refresh_tokens:yl,n71_session_new_fields:Sl,n72_session_primary_key:Tl,n73_drop_sessions:Ol,n74_custom_domains:jl,n75_organizations:Pl,n76_authorization_url_length:Ll,n77_drop_sessions:Bl,n78_login_sessions:Ul,n79_drop_sessions_2:Kl,n80_recreate_custom_domains:Yl,n81_phone:Ql,n82_forms:tu,n83_addFormsIdToHooks:iu,n84_login_completed:su,n85_add_login_session_id_to_sessions:uu,n86_index_sessions_login_session_id:pu,n87_code_challenge:gu,n88_add_redirect_uri_to_codes:yu,n89_add_nonce_and_state_to_codes:Su,n90_themes:Tu,n91_resource_servers_rules_permissions:Ou,n92_role_permissions:ju,n93_add_permissions_to_roles:Pu,n94_keys_connection_and_extend_columns:Lu,n95_create_organizations_table:Bu,n96_create_user_organizations_table:Uu,n97_add_organization_to_user_permissions_and_roles:Ku,n98_clients:Yu,n99_update_client_foreign_keys:ed,o001_client_grants:cd,o002_drop_applications:dd,o003_phone_number_index:md,o004_login_sessions_id_index:_d,o005_connections_tenant_index:bd,o006_remove_redundant_user_organizations_tenant_index:Cd,o007_tenant_settings:Ed,o008_merge_tenant_settings_into_tenants:kd,o009_create_invites_table:Md,o010_add_log_id_to_logs:Fd,o011_add_location_info_to_logs:Rd,o012_add_password_history:Vd,o013_connection_display_name:Wd,o014_client_connections:qd,o015_flows:Xd,o016_add_is_system_column:$d,o017_connections_composite_key:nf,o018_login_session_state:of,o019_roles_resource_servers_metadata:lf,o020_session_add_timestamp_columns:ff,o021_session_cleanup_and_ulid:gf,o022_oidc_profile_claims:bf,o023_preferred_username:Cf,o024_user_address:Ef,o025_authparams_max_age:kf,o026_auth0_conformant:Mf,o027_universal_login_templates:Ff,o028_custom_text:Rf,o029_guardian_mfa:Vf,o030_add_template_id_to_hooks:Wf,o031_hooks_cleanup:Xf,o032_unique_username_provider:tp,o033_add_login_id_to_refresh_tokens:ip,o034_refresh_tokens_replace_session_id_with_login_id:sp,o035_idle_expires_at_ts_indexes:dp,o036_add_connection_to_login_sessions:mp,o037_mfa_enrollments:_p,o038_add_otp_to_codes:bp,o039_rename_mfa_enrollments_to_authentication_methods:Cp,o040_create_outbox_events:Ep,o041_add_outbox_claim_columns:kp,o042_add_outbox_claim_index:Mp,o043_add_code_hooks:Fp,o044_create_actions:Rp,o045_outbox_dead_letter:Vp,o046_user_registration_completed_at:Wp,o047_outbox_dead_lettered_tenant_index:qp,o048_add_auth_strategy_to_login_sessions:Xp,o049_login_sessions_auth_params:$p,o050_login_sessions_auth_params_backfill:rm,o051_relax_login_sessions_authparams:lm,o052_drop_login_sessions_hoisted_authparams:hm,o053_refresh_tokens_revoked_at:Cm,o054_client_registration_tokens:Em,o055_planetscale_redundant_indexes_cleanup:km,o056_client_user_linking_mode:Fm,o057_hooks_metadata:Rm,o058_refresh_tokens_rotation:Vm,o059_organization_connections:Wm,o060_log_streams:qm,o061_tenants_attack_protection:Xm,o062_tenants_default_client_id:$m,o063_email_templates:nh,o064_create_action_versions:ah,o065_branding_dark_mode:ch,o066_create_action_executions:dh,o067_client_disable_sign_ups:mh,o068_move_disable_signup_to_connection:vh,o069_actions_is_system_inherit:Sh,o070_collapse_auth0_source_into_db_connection:Th,o071_migration_sources:Ah,o072_proxy_routes:Nh,o073_proxy_routes_v2:Ih,o074_widen_user_permissions_resource_server_identifier:Vh,o075_create_grants:Gh,o076_default_first_party_true:Jh,o077_tenant_deployment_fields:Zh,o078_tenant_database_version:eg};async function ig(e,t=!1){$u(t),t&&console.log(`migrating...`);let{error:n,results:r}=await new Oa({db:e,provider:new ka(rg)}).migrateToLatest();if(r?.forEach(e=>{e.status===`Success`?t&&console.log(`migration "${e.migrationName}" was executed successfully`):e.status===`Error`&&console.error(`failed to execute migration "${e.migrationName}"`)}),n)throw console.error(`failed to migrate`),console.error(n),n}async function ag(e,t=!1){$u(t),t&&console.log(`migrating...`);let{error:n,results:r}=await new Oa({db:e,provider:new ka(rg)}).migrateDown();if(r?.forEach(e=>{e.status===`Success`?t&&console.log(`migration "${e.migrationName}" was reverted successfully`):e.status===`Error`&&console.error(`failed to execute migration "${e.migrationName}"`)}),n)throw console.error(`failed to migrate`),console.error(n),n}function og(e,t={useTransactions:!0}){let n={actions:oe(e),actionExecutions:ue(e),actionVersions:pe(e),branding:mn(e),clients:kt(e),clientConnections:Ft(e),clientGrants:Vt(e),clientRegistrationTokens:$t(e),codes:mt(e),connections:St(e),emailProviders:tr(e),emailTemplates:cr(e),customDomains:dn(e),flows:Me(e),forms:Tr(e),hookCode:kn(e),hooks:wn(e),invites:Ci(e),keys:rn(e),loginSessions:Kn(e),logs:Xe(e),logStreams:aa(e),migrationSources:oa(e),authenticationMethods:qi(e),passwords:st(e),promptSettings:Xn(e),proxyRoutes:z(e),refreshTokens:_r(e),resourceServers:jr(e),rolePermissions:Vr(e),grants:qr(e),userPermissions:Qr(e),userRoles:ri(e),roles:Lr(e),sessions:nt(e),sessionCleanup:yr(e),tenants:He(e),themes:Pn(e),universalLoginTemplates:vn(e),customText:Bi(e),users:we(e),organizations:li(e),organizationConnections:ui(e),userOrganizations:_i(e),stats:Oi(e),analytics:zi(e),outbox:ia(e),async transaction(r){return t.useTransactions===!1?r(n):e.transaction().execute(async e=>r(og(e,{...t,useTransactions:!1})))}};return n}exports.createProxyDataAdapter=ua,exports.createProxyRoutesAdapter=z,exports.default=og,exports.migrateDown=ag,exports.migrateToLatest=ig;
|
package/dist/kysely-adapter.d.ts
CHANGED
|
@@ -524,6 +524,7 @@ declare const sqlTenantSchema: z.ZodObject<{
|
|
|
524
524
|
provisioning_state_changed_at: z.ZodOptional<z.ZodString>;
|
|
525
525
|
bundle_configuration: z.ZodOptional<z.ZodString>;
|
|
526
526
|
worker_version: z.ZodOptional<z.ZodString>;
|
|
527
|
+
database_version: z.ZodOptional<z.ZodString>;
|
|
527
528
|
worker_script_name: z.ZodOptional<z.ZodString>;
|
|
528
529
|
storage_kind: z.ZodOptional<z.ZodEnum<{
|
|
529
530
|
own_d1: "own_d1";
|
package/dist/kysely-adapter.mjs
CHANGED
|
@@ -9358,8 +9358,20 @@ async function fg(e) {
|
|
|
9358
9358
|
await e.schema.alterTable("tenants").dropColumn("d1_database_id").execute(), await e.schema.alterTable("tenants").dropColumn("storage_kind").execute(), await e.schema.alterTable("tenants").dropColumn("worker_script_name").execute(), await e.schema.alterTable("tenants").dropColumn("worker_version").execute(), await e.schema.alterTable("tenants").dropColumn("bundle_configuration").execute(), await e.schema.alterTable("tenants").dropColumn("provisioning_state_changed_at").execute(), await e.schema.alterTable("tenants").dropColumn("provisioning_error").execute(), await e.schema.alterTable("tenants").dropColumn("provisioning_state").execute(), await e.schema.alterTable("tenants").dropColumn("deployment_type").execute();
|
|
9359
9359
|
}
|
|
9360
9360
|
//#endregion
|
|
9361
|
+
//#region migrate/migrations/2026-06-27T12:00:00_tenant_database_version.ts
|
|
9362
|
+
var pg = /* @__PURE__ */ _({
|
|
9363
|
+
down: () => hg,
|
|
9364
|
+
up: () => mg
|
|
9365
|
+
});
|
|
9366
|
+
async function mg(e) {
|
|
9367
|
+
await e.schema.alterTable("tenants").addColumn("database_version", "varchar(64)").execute();
|
|
9368
|
+
}
|
|
9369
|
+
async function hg(e) {
|
|
9370
|
+
await e.schema.alterTable("tenants").dropColumn("database_version").execute();
|
|
9371
|
+
}
|
|
9372
|
+
//#endregion
|
|
9361
9373
|
//#region migrate/migrations/index.ts
|
|
9362
|
-
var
|
|
9374
|
+
var gg = {
|
|
9363
9375
|
m1_init: Wa,
|
|
9364
9376
|
m2_magicLink: qa,
|
|
9365
9377
|
m3_updateAt: Xa,
|
|
@@ -9534,25 +9546,26 @@ var pg = {
|
|
|
9534
9546
|
o074_widen_user_permissions_resource_server_identifier: eg,
|
|
9535
9547
|
o075_create_grants: ig,
|
|
9536
9548
|
o076_default_first_party_true: sg,
|
|
9537
|
-
o077_tenant_deployment_fields: ug
|
|
9549
|
+
o077_tenant_deployment_fields: ug,
|
|
9550
|
+
o078_tenant_database_version: pg
|
|
9538
9551
|
};
|
|
9539
9552
|
//#endregion
|
|
9540
9553
|
//#region migrate/migrate.ts
|
|
9541
|
-
async function
|
|
9554
|
+
async function _g(e, t = !1) {
|
|
9542
9555
|
pd(t), t && console.log("migrating...");
|
|
9543
9556
|
let { error: n, results: r } = await new Va({
|
|
9544
9557
|
db: e,
|
|
9545
|
-
provider: new Ua(
|
|
9558
|
+
provider: new Ua(gg)
|
|
9546
9559
|
}).migrateToLatest();
|
|
9547
9560
|
if (r?.forEach((e) => {
|
|
9548
9561
|
e.status === "Success" ? t && console.log(`migration "${e.migrationName}" was executed successfully`) : e.status === "Error" && console.error(`failed to execute migration "${e.migrationName}"`);
|
|
9549
9562
|
}), n) throw console.error("failed to migrate"), console.error(n), n;
|
|
9550
9563
|
}
|
|
9551
|
-
async function
|
|
9564
|
+
async function vg(e, t = !1) {
|
|
9552
9565
|
pd(t), t && console.log("migrating...");
|
|
9553
9566
|
let { error: n, results: r } = await new Va({
|
|
9554
9567
|
db: e,
|
|
9555
|
-
provider: new Ua(
|
|
9568
|
+
provider: new Ua(gg)
|
|
9556
9569
|
}).migrateDown();
|
|
9557
9570
|
if (r?.forEach((e) => {
|
|
9558
9571
|
e.status === "Success" ? t && console.log(`migration "${e.migrationName}" was reverted successfully`) : e.status === "Error" && console.error(`failed to execute migration "${e.migrationName}"`);
|
|
@@ -9560,7 +9573,7 @@ async function hg(e, t = !1) {
|
|
|
9560
9573
|
}
|
|
9561
9574
|
//#endregion
|
|
9562
9575
|
//#region src/index.ts
|
|
9563
|
-
function
|
|
9576
|
+
function yg(e, t = { useTransactions: !0 }) {
|
|
9564
9577
|
let n = {
|
|
9565
9578
|
actions: ve(e),
|
|
9566
9579
|
actionExecutions: Se(e),
|
|
@@ -9610,7 +9623,7 @@ function gg(e, t = { useTransactions: !0 }) {
|
|
|
9610
9623
|
analytics: qi(e),
|
|
9611
9624
|
outbox: fa(e),
|
|
9612
9625
|
async transaction(r) {
|
|
9613
|
-
return t.useTransactions === !1 ? r(n) : e.transaction().execute(async (e) => r(
|
|
9626
|
+
return t.useTransactions === !1 ? r(n) : e.transaction().execute(async (e) => r(yg(e, {
|
|
9614
9627
|
...t,
|
|
9615
9628
|
useTransactions: !1
|
|
9616
9629
|
})));
|
|
@@ -9619,4 +9632,4 @@ function gg(e, t = { useTransactions: !0 }) {
|
|
|
9619
9632
|
return n;
|
|
9620
9633
|
}
|
|
9621
9634
|
//#endregion
|
|
9622
|
-
export { ba as createProxyDataAdapter, va as createProxyRoutesAdapter,
|
|
9635
|
+
export { ba as createProxyDataAdapter, va as createProxyRoutesAdapter, yg as default, vg as migrateDown, _g as migrateToLatest };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
import { Database } from "../../src/db";
|
|
3
|
+
/**
|
|
4
|
+
* Adds `database_version` to the tenant row so the control plane can record the
|
|
5
|
+
* schema version (the latest migration applied) the deployed WFP tenant worker
|
|
6
|
+
* targets. Together with `worker_version` and `bundle_configuration` this lets
|
|
7
|
+
* the control plane detect drift and drive upgrades. Nullable — shared tenants
|
|
8
|
+
* and pre-existing WFP tenants land as `null` until their next (re)provision.
|
|
9
|
+
*/
|
|
10
|
+
export declare function up(db: Kysely<Database>): Promise<void>;
|
|
11
|
+
export declare function down(db: Kysely<Database>): Promise<void>;
|
|
@@ -173,6 +173,7 @@ import * as o074_widen_user_permissions_resource_server_identifier from "./2026-
|
|
|
173
173
|
import * as o075_create_grants from "./2026-06-04T11:00:00_create_grants";
|
|
174
174
|
import * as o076_default_first_party_true from "./2026-06-04T11:01:00_default_first_party_true";
|
|
175
175
|
import * as o077_tenant_deployment_fields from "./2026-06-06T12:00:00_tenant_deployment_fields";
|
|
176
|
+
import * as o078_tenant_database_version from "./2026-06-27T12:00:00_tenant_database_version";
|
|
176
177
|
declare const _default: {
|
|
177
178
|
m1_init: typeof m1_init;
|
|
178
179
|
m2_magicLink: typeof m2_magicLink;
|
|
@@ -349,5 +350,6 @@ declare const _default: {
|
|
|
349
350
|
o075_create_grants: typeof o075_create_grants;
|
|
350
351
|
o076_default_first_party_true: typeof o076_default_first_party_true;
|
|
351
352
|
o077_tenant_deployment_fields: typeof o077_tenant_deployment_fields;
|
|
353
|
+
o078_tenant_database_version: typeof o078_tenant_database_version;
|
|
352
354
|
};
|
|
353
355
|
export default _default;
|
package/dist/types/src/db.d.ts
CHANGED
|
@@ -524,6 +524,7 @@ export declare const sqlTenantSchema: z.ZodObject<{
|
|
|
524
524
|
provisioning_state_changed_at: z.ZodOptional<z.ZodString>;
|
|
525
525
|
bundle_configuration: z.ZodOptional<z.ZodString>;
|
|
526
526
|
worker_version: z.ZodOptional<z.ZodString>;
|
|
527
|
+
database_version: z.ZodOptional<z.ZodString>;
|
|
527
528
|
worker_script_name: z.ZodOptional<z.ZodString>;
|
|
528
529
|
storage_kind: z.ZodOptional<z.ZodEnum<{
|
|
529
530
|
own_d1: "own_d1";
|
|
@@ -115,6 +115,7 @@ export declare function list(db: Kysely<Database>): (params?: ListParams) => Pro
|
|
|
115
115
|
provisioning_state_changed_at?: string | undefined;
|
|
116
116
|
bundle_configuration?: string | undefined;
|
|
117
117
|
worker_version?: string | undefined;
|
|
118
|
+
database_version?: string | undefined;
|
|
118
119
|
worker_script_name?: string | undefined;
|
|
119
120
|
storage_kind?: "own_d1" | "existing_d1" | "shared_planetscale" | undefined;
|
|
120
121
|
d1_database_id?: string | undefined;
|
|
@@ -300,6 +301,7 @@ export declare function list(db: Kysely<Database>): (params?: ListParams) => Pro
|
|
|
300
301
|
provisioning_state_changed_at?: string | undefined;
|
|
301
302
|
bundle_configuration?: string | undefined;
|
|
302
303
|
worker_version?: string | undefined;
|
|
304
|
+
database_version?: string | undefined;
|
|
303
305
|
worker_script_name?: string | undefined;
|
|
304
306
|
storage_kind?: "own_d1" | "existing_d1" | "shared_planetscale" | undefined;
|
|
305
307
|
d1_database_id?: string | undefined;
|