@stacksjs/buddy 0.71.10 → 0.72.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/commands/migrate.js +1 -1
- package/dist/commands/seed.js +1 -1
- package/package.json +45 -45
package/dist/commands/migrate.js
CHANGED
|
@@ -17,7 +17,7 @@ ${sample}${more}
|
|
|
17
17
|
`);process.exit(ExitCode.FatalError)}const guards=await resolveMigrationGuards(),dbLabel=currentDatabaseLabel(),APP_ENV=process.env.APP_ENV||"local";if(guards.migrateFresh==="disabled"){await log.error(`\`buddy migrate:fresh\` is disabled by your migration safety guards (it DROPS every table).
|
|
18
18
|
Target: ${APP_ENV} database "${dbLabel}"
|
|
19
19
|
To allow it, set database.safety.migrateFresh to 'allow' in config/database.ts,
|
|
20
|
-
or run once with: DB_MIGRATE_FRESH=allow ./buddy migrate:fresh`);await outro('migrate:fresh refused \u2014 the migrateFresh guard is set to "disabled".',{startTime:perf,useSeconds:!0});process.exit(ExitCode.FatalError)}if(!(guards.migrateFresh==="allow"&&options.force===!0)){if(isCI||!hasTTY){const hint=guards.migrateFresh==="confirm"?'Guard is "confirm": migrate:fresh must be run interactively.':"Re-run with --force to drop the database non-interactively.";await log.error(`Refusing to drop the ${APP_ENV} database "${dbLabel}" in a non-interactive environment. ${hint}`);await outro("migrate:fresh cancelled.",{startTime:perf,useSeconds:!0});process.exit(ExitCode.FatalError)}log.warn(`This will DROP ALL TABLES in the ${APP_ENV} database "${dbLabel}" and rebuild them from scratch. All data will be lost.`);await log.flush();if((await text({message:`Type the database name "${dbLabel}" to confirm (blank to cancel):`})).trim()!==dbLabel){await outro("migrate:fresh cancelled \u2014 confirmation did not match.",{startTime:perf,useSeconds:!0});process.exit(ExitCode.Success)}}await preflightDatabase({createDatabase:options.createDatabase,command:"migrate:fresh"});await ensureDatabaseOrExit();const result=await runAction(Action.MigrateFresh,options);if(resultFailed(result))log.error("Model migrations failed \u2014 applying auth/notification/RBAC table guarantees before exiting.");if(options.auth!==!1){log.debug("Migrating auth tables...");try{const{migrateAuthTables,migrateNotificationTables,migrateRbacTables,migrateTraitTables}=await import("@stacksjs/database"),authResult=await migrateAuthTables({verbose:options.verbose});if(!authResult.success)log.error(`Failed to migrate auth tables: ${authResult.error}`);const notifResult=await migrateNotificationTables({verbose:options.verbose});if(!notifResult.success)log.error(`Failed to migrate notification tables: ${notifResult.error}`);const rbacResult=await migrateRbacTables({verbose:options.verbose});if(!rbacResult.success)log.error(`Failed to migrate RBAC tables: ${rbacResult.error}`);const traitResult=await migrateTraitTables({verbose:options.verbose});if(!traitResult.success)log.error(`Failed to migrate polymorphic trait tables: ${traitResult.error}`)}catch(error){log.error("Failed to migrate auth/notification/RBAC/trait tables:",error)}}try{const{ensureUuidColumns,sqlHelpers}=await import("@stacksjs/database"),driver=process.env.DB_CONNECTION||"sqlite";await ensureUuidColumns(sqlHelpers(driver),{verbose:options.verbose})}catch(error){log.error("Failed to ensure uuid columns post-migration:",error)}if(resultFailed(result)){await outro("While running the migrate:fresh command, there was an issue",{startTime:perf,useSeconds:!0},result.error);process.exit(ExitCode.FatalError)}await reportMissingForeignKeys();await reportSchemaDrift();if(options.seed){log.info("Running database seeders...");try{const{seed}=await import("@stacksjs/database"),seedResult=await seed({verbose:options.verbose,fresh:!0})
|
|
20
|
+
or run once with: DB_MIGRATE_FRESH=allow ./buddy migrate:fresh`);await outro('migrate:fresh refused \u2014 the migrateFresh guard is set to "disabled".',{startTime:perf,useSeconds:!0});process.exit(ExitCode.FatalError)}if(!(guards.migrateFresh==="allow"&&options.force===!0)){if(isCI||!hasTTY){const hint=guards.migrateFresh==="confirm"?'Guard is "confirm": migrate:fresh must be run interactively.':"Re-run with --force to drop the database non-interactively.";await log.error(`Refusing to drop the ${APP_ENV} database "${dbLabel}" in a non-interactive environment. ${hint}`);await outro("migrate:fresh cancelled.",{startTime:perf,useSeconds:!0});process.exit(ExitCode.FatalError)}log.warn(`This will DROP ALL TABLES in the ${APP_ENV} database "${dbLabel}" and rebuild them from scratch. All data will be lost.`);await log.flush();if((await text({message:`Type the database name "${dbLabel}" to confirm (blank to cancel):`})).trim()!==dbLabel){await outro("migrate:fresh cancelled \u2014 confirmation did not match.",{startTime:perf,useSeconds:!0});process.exit(ExitCode.Success)}}await preflightDatabase({createDatabase:options.createDatabase,command:"migrate:fresh"});await ensureDatabaseOrExit();const result=await runAction(Action.MigrateFresh,options);if(resultFailed(result))log.error("Model migrations failed \u2014 applying auth/notification/RBAC table guarantees before exiting.");if(options.auth!==!1){log.debug("Migrating auth tables...");try{const{migrateAuthTables,migrateNotificationTables,migrateRbacTables,migrateTraitTables}=await import("@stacksjs/database"),authResult=await migrateAuthTables({verbose:options.verbose});if(!authResult.success)log.error(`Failed to migrate auth tables: ${authResult.error}`);const notifResult=await migrateNotificationTables({verbose:options.verbose});if(!notifResult.success)log.error(`Failed to migrate notification tables: ${notifResult.error}`);const rbacResult=await migrateRbacTables({verbose:options.verbose});if(!rbacResult.success)log.error(`Failed to migrate RBAC tables: ${rbacResult.error}`);const traitResult=await migrateTraitTables({verbose:options.verbose});if(!traitResult.success)log.error(`Failed to migrate polymorphic trait tables: ${traitResult.error}`)}catch(error){log.error("Failed to migrate auth/notification/RBAC/trait tables:",error)}}try{const{ensureUuidColumns,sqlHelpers}=await import("@stacksjs/database"),driver=process.env.DB_CONNECTION||"sqlite";await ensureUuidColumns(sqlHelpers(driver),{verbose:options.verbose})}catch(error){log.error("Failed to ensure uuid columns post-migration:",error)}if(resultFailed(result)){await outro("While running the migrate:fresh command, there was an issue",{startTime:perf,useSeconds:!0},result.error);process.exit(ExitCode.FatalError)}await reportMissingForeignKeys();await reportSchemaDrift();if(options.seed){log.info("Running database seeders...");try{const{runApplicationSeeders,seed}=await import("@stacksjs/database"),seedResult=await seed({verbose:options.verbose,fresh:!0}),applicationSeedResult=await runApplicationSeeders({verbose:options.verbose}),failures=seedResult.failed+applicationSeedResult.failed;if(failures>0){log.warn(`Seeding completed with ${failures} failure(s)`);for(const r of seedResult.results)if(!r.success)log.error(` - ${r.model}: ${r.error}`);for(const r of applicationSeedResult.results)if(!r.success)log.error(` - ${r.seeder}: ${r.error}`)}else log.success(`Seeded ${seedResult.successful} model(s) and ran ${applicationSeedResult.successful} application seeder(s)`)}catch(error){log.error("Failed to run seeders:",error)}}const parts=[];if(options.auth!==!1)parts.push("auth tables");if(options.seed)parts.push("seeded");const suffix=parts.length>0?` & ${parts.join(" & ")}`:"",marker=readMigrateMarker(),countPhrase=marker==null?"":marker.appliedCount===0?" (0 applied \u2014 no migration files found?)":` (${marker.appliedCount} migration${marker.appliedCount===1?"":"s"} applied)`;await outro(`All tables dropped successfully & migrated successfully${countPhrase}${suffix}`,{startTime:perf,useSeconds:!0});process.exit(ExitCode.Success)});buddy.command("migrate:dns",descriptions.migrate).option("-p, --project [project]",descriptions.project,{default:!1}).option("--verbose",descriptions.verbose,{default:!1}).action(async(options)=>{log.debug("Running `buddy migrate:dns` ...",options);const perf=await intro("buddy migrate:dns"),result=await runAction(Action.MigrateDns,{...options});if(resultFailed(result)){await outro("While running the migrate:dns command, there was an issue",{startTime:perf,useSeconds:!0},result.error);process.exit(ExitCode.FatalError)}const APP_URL=process.env.APP_URL||"undefined";await outro(`Migrated your ${APP_URL} DNS.`,{startTime:perf,useSeconds:!0});process.exit(ExitCode.Success)});buddy.command("migrate:switch <driver>","Pre-flight check + plan for switching DB_CONNECTION between sqlite / mysql / vitess / postgres").action(async(driver)=>{log.debug(`Running \`buddy migrate:switch ${driver}\` ...`);const perf=await intro("buddy migrate:switch"),target=driver.toLowerCase();if(!new Set(["sqlite","mysql","vitess","postgres"]).has(target)){console.log(`
|
|
21
21
|
Unknown target driver "${driver}". Allowed: sqlite, mysql, vitess, postgres.
|
|
22
22
|
`);await outro("Aborted.",{startTime:perf,useSeconds:!0});process.exit(ExitCode.FatalError)}const current=(process.env.DB_CONNECTION||"sqlite").toLowerCase();if(current===target){console.log(`
|
|
23
23
|
DB_CONNECTION is already "${target}". Nothing to switch.
|
package/dist/commands/seed.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import process from"node:process";import{intro,log,onUnknownSubcommand,outro}from"@stacksjs/cli";import{ExitCode}from"@stacksjs/types";export function seed(buddy){const descriptions={seed:"Seed your database",project:"Target a specific project",verbose:"Enable verbose output"};buddy.command("seed",descriptions.seed).alias("db:seed").option("-p, --project [project]",descriptions.project,{default:!1}).option("--only [models]","Comma-separated list of models to seed",{default:""}).option("--except [models]","Comma-separated list of models to skip",{default:""}).option("--include-defaults","Also seed the framework's built-in models",{default:!1}).option("--allow-protected","Seed auth/oauth models even on a non-fresh DB (will invalidate live tokens)",{default:!1}).option("--fresh","Truncate tables before seeding",{default:!1}).option("--append","Add rows to tables that already have some, instead of skipping them",{default:!1}).option("--verbose",descriptions.verbose,{default:!1}).action(async(options)=>{log.debug("Running `buddy seed` ...",options);const perf=await intro("buddy seed"),{injectGlobalAutoImports}=await import("@stacksjs/server");await injectGlobalAutoImports();const{seed:seedDatabase}=await import("@stacksjs/database"),list=(value)=>value?value.split(",").map((entry)=>entry.trim()).filter(Boolean):void 0,summary=await seedDatabase({verbose:options.verbose,fresh:options.fresh,append:options.append,only:list(options.only),except:list(options.except),includeDefaults:options.includeDefaults,allowProtected:options.allowProtected}),APP_ENV=process.env.APP_ENV||"local";if(summary.total===0){await outro("No models declare a `useSeeder` trait
|
|
1
|
+
import process from"node:process";import{intro,log,onUnknownSubcommand,outro}from"@stacksjs/cli";import{ExitCode}from"@stacksjs/types";export function seed(buddy){const descriptions={seed:"Seed your database",project:"Target a specific project",verbose:"Enable verbose output"};buddy.command("seed",descriptions.seed).alias("db:seed").option("-p, --project [project]",descriptions.project,{default:!1}).option("--only [models]","Comma-separated list of models to seed",{default:""}).option("--except [models]","Comma-separated list of models to skip",{default:""}).option("--include-defaults","Also seed the framework's built-in models",{default:!1}).option("--allow-protected","Seed auth/oauth models even on a non-fresh DB (will invalidate live tokens)",{default:!1}).option("--fresh","Truncate tables before seeding",{default:!1}).option("--append","Add rows to tables that already have some, instead of skipping them",{default:!1}).option("--verbose",descriptions.verbose,{default:!1}).action(async(options)=>{log.debug("Running `buddy seed` ...",options);const perf=await intro("buddy seed"),{injectGlobalAutoImports}=await import("@stacksjs/server");await injectGlobalAutoImports();const{runApplicationSeeders,seed:seedDatabase}=await import("@stacksjs/database"),list=(value)=>value?value.split(",").map((entry)=>entry.trim()).filter(Boolean):void 0,summary=await seedDatabase({verbose:options.verbose,fresh:options.fresh,append:options.append,only:list(options.only),except:list(options.except),includeDefaults:options.includeDefaults,allowProtected:options.allowProtected}),applicationSummary=await runApplicationSeeders({verbose:options.verbose}),APP_ENV=process.env.APP_ENV||"local";if(summary.total===0&&applicationSummary.total===0){await outro("No models declare a `useSeeder` trait and no application seeders were found.",{startTime:perf,useSeconds:!0});process.exit(ExitCode.Success)}const failures=summary.failed+applicationSummary.failed;await outro(`Seeded your ${APP_ENV} database. ${summary.successful}/${summary.total} model(s) and ${applicationSummary.successful}/${applicationSummary.total} application seeder(s) completed${failures>0?`, ${failures} failed`:""}.`,{startTime:perf,useSeconds:!0});process.exit(failures>0?ExitCode.FatalError:ExitCode.Success)});buddy.command("seed:roles","Seed default RBAC role packs (admin, dev, client)").alias("roles:seed").action(async()=>{const perf=await intro("buddy seed:roles");try{const{seedDefaultRoles}=await import("@stacksjs/auth"),result=await seedDefaultRoles();if(result.created.length===0&&result.skipped.length>0)await outro(`All ${result.skipped.length} default role packs already exist \u2014 nothing to do.`,{startTime:perf,useSeconds:!0});else{const createdNames=result.created.map((r)=>r.name).join(", ");await outro(`Created ${result.created.length} role pack(s): ${createdNames}. Skipped ${result.skipped.length} existing.`,{startTime:perf,useSeconds:!0})}process.exit(ExitCode.Success)}catch(err){await outro("Failed to seed default roles. Most often: migrations haven't run yet (try `./buddy migrate` first).",{startTime:perf,useSeconds:!0},err);process.exit(ExitCode.FatalError)}});onUnknownSubcommand(buddy,"seed")}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/buddy",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.72.0",
|
|
6
6
|
"description": "Meet Buddy. The Stacks runtime.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -95,55 +95,55 @@
|
|
|
95
95
|
"prepublishOnly": "bun run build"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@stacksjs/actions": "^0.
|
|
99
|
-
"@stacksjs/ai": "^0.
|
|
100
|
-
"@stacksjs/alias": "^0.
|
|
101
|
-
"@stacksjs/arrays": "^0.
|
|
102
|
-
"@stacksjs/auth": "^0.
|
|
103
|
-
"@stacksjs/build": "^0.
|
|
104
|
-
"@stacksjs/cache": "^0.
|
|
105
|
-
"@stacksjs/cli": "^0.
|
|
98
|
+
"@stacksjs/actions": "^0.72.0",
|
|
99
|
+
"@stacksjs/ai": "^0.72.0",
|
|
100
|
+
"@stacksjs/alias": "^0.72.0",
|
|
101
|
+
"@stacksjs/arrays": "^0.72.0",
|
|
102
|
+
"@stacksjs/auth": "^0.72.0",
|
|
103
|
+
"@stacksjs/build": "^0.72.0",
|
|
104
|
+
"@stacksjs/cache": "^0.72.0",
|
|
105
|
+
"@stacksjs/cli": "^0.72.0",
|
|
106
106
|
"@stacksjs/clapp": "^0.2.12",
|
|
107
|
-
"@stacksjs/cloud": "^0.
|
|
108
|
-
"@stacksjs/collections": "^0.
|
|
109
|
-
"@stacksjs/config": "^0.
|
|
110
|
-
"@stacksjs/database": "^0.
|
|
111
|
-
"@stacksjs/desktop-build": "^0.
|
|
112
|
-
"@stacksjs/dns": "^0.
|
|
113
|
-
"@stacksjs/email": "^0.
|
|
114
|
-
"@stacksjs/enums": "^0.
|
|
115
|
-
"@stacksjs/error-handling": "^0.
|
|
116
|
-
"@stacksjs/events": "^0.
|
|
117
|
-
"@stacksjs/git": "^0.
|
|
107
|
+
"@stacksjs/cloud": "^0.72.0",
|
|
108
|
+
"@stacksjs/collections": "^0.72.0",
|
|
109
|
+
"@stacksjs/config": "^0.72.0",
|
|
110
|
+
"@stacksjs/database": "^0.72.0",
|
|
111
|
+
"@stacksjs/desktop-build": "^0.72.0",
|
|
112
|
+
"@stacksjs/dns": "^0.72.0",
|
|
113
|
+
"@stacksjs/email": "^0.72.0",
|
|
114
|
+
"@stacksjs/enums": "^0.72.0",
|
|
115
|
+
"@stacksjs/error-handling": "^0.72.0",
|
|
116
|
+
"@stacksjs/events": "^0.72.0",
|
|
117
|
+
"@stacksjs/git": "^0.72.0",
|
|
118
118
|
"@stacksjs/gitit": "^0.2.5",
|
|
119
|
-
"@stacksjs/health": "^0.
|
|
119
|
+
"@stacksjs/health": "^0.72.0",
|
|
120
120
|
"@stacksjs/dnsx": "^0.2.3",
|
|
121
121
|
"@stacksjs/httx": "^0.1.10",
|
|
122
|
-
"@stacksjs/image": "^0.
|
|
123
|
-
"@stacksjs/lint": "^0.
|
|
124
|
-
"@stacksjs/logging": "^0.
|
|
125
|
-
"@stacksjs/notifications": "^0.
|
|
126
|
-
"@stacksjs/objects": "^0.
|
|
127
|
-
"@stacksjs/orm": "^0.
|
|
128
|
-
"@stacksjs/path": "^0.
|
|
129
|
-
"@stacksjs/skills": "^0.
|
|
130
|
-
"@stacksjs/payments": "^0.
|
|
131
|
-
"@stacksjs/realtime": "^0.
|
|
132
|
-
"@stacksjs/router": "^0.
|
|
122
|
+
"@stacksjs/image": "^0.72.0",
|
|
123
|
+
"@stacksjs/lint": "^0.72.0",
|
|
124
|
+
"@stacksjs/logging": "^0.72.0",
|
|
125
|
+
"@stacksjs/notifications": "^0.72.0",
|
|
126
|
+
"@stacksjs/objects": "^0.72.0",
|
|
127
|
+
"@stacksjs/orm": "^0.72.0",
|
|
128
|
+
"@stacksjs/path": "^0.72.0",
|
|
129
|
+
"@stacksjs/skills": "^0.72.0",
|
|
130
|
+
"@stacksjs/payments": "^0.72.0",
|
|
131
|
+
"@stacksjs/realtime": "^0.72.0",
|
|
132
|
+
"@stacksjs/router": "^0.72.0",
|
|
133
133
|
"@stacksjs/rpx": "^0.11.42",
|
|
134
|
-
"@stacksjs/search-engine": "^0.
|
|
135
|
-
"@stacksjs/security": "^0.
|
|
136
|
-
"@stacksjs/server": "^0.
|
|
137
|
-
"@stacksjs/cms": "^0.
|
|
138
|
-
"@stacksjs/sites": "^0.
|
|
139
|
-
"@stacksjs/storage": "^0.
|
|
140
|
-
"@stacksjs/strings": "^0.
|
|
141
|
-
"@stacksjs/testing": "^0.
|
|
142
|
-
"@stacksjs/tunnel": "^0.
|
|
143
|
-
"@stacksjs/types": "^0.
|
|
144
|
-
"@stacksjs/ui": "^0.
|
|
145
|
-
"@stacksjs/utils": "^0.
|
|
146
|
-
"@stacksjs/validation": "^0.
|
|
134
|
+
"@stacksjs/search-engine": "^0.72.0",
|
|
135
|
+
"@stacksjs/security": "^0.72.0",
|
|
136
|
+
"@stacksjs/server": "^0.72.0",
|
|
137
|
+
"@stacksjs/cms": "^0.72.0",
|
|
138
|
+
"@stacksjs/sites": "^0.72.0",
|
|
139
|
+
"@stacksjs/storage": "^0.72.0",
|
|
140
|
+
"@stacksjs/strings": "^0.72.0",
|
|
141
|
+
"@stacksjs/testing": "^0.72.0",
|
|
142
|
+
"@stacksjs/tunnel": "^0.72.0",
|
|
143
|
+
"@stacksjs/types": "^0.72.0",
|
|
144
|
+
"@stacksjs/ui": "^0.72.0",
|
|
145
|
+
"@stacksjs/utils": "^0.72.0",
|
|
146
|
+
"@stacksjs/validation": "^0.72.0",
|
|
147
147
|
"@stacksjs/ts-cloud": "^0.8.3",
|
|
148
148
|
"ajv": "^8.20.0",
|
|
149
149
|
"ajv-formats": "^3.0.1",
|