Skip to content

Commit 533473f

Browse files
committed
feat(app-plugin): add data seeding functionality during plugin start
1 parent 23f2220 commit 533473f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

packages/runtime/src/app-plugin.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,29 @@ export class AppPlugin implements Plugin {
9797
} else {
9898
ctx.logger.debug('No runtime.onEnable function found', { appId });
9999
}
100+
101+
// Data Seeding
102+
// Check for 'data' in manifest (Legacy or Stack Definition)
103+
const manifest = this.bundle.manifest || this.bundle;
104+
if (manifest && Array.isArray(manifest.data)) {
105+
ctx.logger.info(`[AppPlugin] Found initial data for ${appId}`, { count: manifest.data.length });
106+
for (const dataset of manifest.data) {
107+
if (dataset.object && Array.isArray(dataset.records)) {
108+
ctx.logger.info(`[Seeder] Seeding ${dataset.records.length} records for ${dataset.object}`);
109+
for (const record of dataset.records) {
110+
try {
111+
// Use ObjectQL engine to insert data
112+
// This ensures driver resolution and hook execution
113+
// Use 'insert' which corresponds to 'create' in driver
114+
await ql.insert(dataset.object, record);
115+
} catch (err: any) {
116+
// Ignore duplicate errors if needed, or log/warn
117+
ctx.logger.warn(`[Seeder] Failed to insert ${dataset.object} record:`, { error: err.message });
118+
}
119+
}
120+
}
121+
}
122+
ctx.logger.info('[Seeder] Data seeding complete.');
123+
}
100124
}
101125
}

0 commit comments

Comments
 (0)