feat: share dashboard & reports, sankey report, new widgets
* fix: prompt card shadows on light mode * fix: handle past_due and unpaid from polar * wip * wip * wip 1 * fix: improve types for chart/reports * wip share
This commit is contained in:
committed by
GitHub
parent
39251c8598
commit
ed1c57dbb8
90
packages/db/code-migrations/9-migrate-options.ts
Normal file
90
packages/db/code-migrations/9-migrate-options.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import type { IReportOptions } from '@openpanel/validation';
|
||||
import { db } from '../index';
|
||||
import { printBoxMessage } from './helpers';
|
||||
|
||||
export async function up() {
|
||||
printBoxMessage('🔄 Migrating Legacy Fields to Options', []);
|
||||
|
||||
// Get all reports
|
||||
const reports = await db.report.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
chartType: true,
|
||||
funnelGroup: true,
|
||||
funnelWindow: true,
|
||||
criteria: true,
|
||||
options: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
|
||||
let migratedCount = 0;
|
||||
let skippedCount = 0;
|
||||
|
||||
for (const report of reports) {
|
||||
const currentOptions = report.options as IReportOptions | null | undefined;
|
||||
|
||||
// Skip if options already exists and is valid
|
||||
if (
|
||||
currentOptions &&
|
||||
typeof currentOptions === 'object' &&
|
||||
'type' in currentOptions
|
||||
) {
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
let newOptions: IReportOptions | null = null;
|
||||
|
||||
// Migrate based on chart type
|
||||
if (report.chartType === 'funnel') {
|
||||
// Only create options if we have legacy fields to migrate
|
||||
if (report.funnelGroup || report.funnelWindow !== null) {
|
||||
newOptions = {
|
||||
type: 'funnel',
|
||||
funnelGroup: report.funnelGroup ?? undefined,
|
||||
funnelWindow: report.funnelWindow ?? undefined,
|
||||
};
|
||||
}
|
||||
} else if (report.chartType === 'retention') {
|
||||
// Only create options if we have criteria to migrate
|
||||
if (report.criteria) {
|
||||
newOptions = {
|
||||
type: 'retention',
|
||||
criteria: report.criteria as 'on_or_after' | 'on' | undefined,
|
||||
};
|
||||
}
|
||||
} else if (report.chartType === 'sankey') {
|
||||
// Sankey should already have options, but if not, skip
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only update if we have new options to set
|
||||
if (newOptions) {
|
||||
console.log(
|
||||
`Migrating report ${report.name} (${report.id}) - chartType: ${report.chartType}`,
|
||||
);
|
||||
|
||||
await db.report.update({
|
||||
where: { id: report.id },
|
||||
data: {
|
||||
options: newOptions,
|
||||
// Set legacy fields to null after migration
|
||||
funnelGroup: null,
|
||||
funnelWindow: null,
|
||||
criteria: report.chartType === 'retention' ? null : report.criteria,
|
||||
},
|
||||
});
|
||||
|
||||
migratedCount++;
|
||||
} else {
|
||||
skippedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
printBoxMessage('✅ Migration Complete', [
|
||||
`Migrated: ${migratedCount} reports`,
|
||||
`Skipped: ${skippedCount} reports (already migrated or no legacy fields)`,
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user