From fd2deece1664c7258f483bdc64bd1452255a52d4 Mon Sep 17 00:00:00 2001 From: WhyAsh5114 Date: Wed, 16 Oct 2024 16:42:41 +0530 Subject: [PATCH] feat: add v2 migration flag to user schema --- .../migration.sql | 2 + prisma/schema/schema.prisma | 1 + src/lib/trpc/routes/users.ts | 11 +- src/lib/zodSchemas/index.ts | 47 +++++++- src/routes/profile/+page.svelte | 104 +++++++++--------- 5 files changed, 108 insertions(+), 57 deletions(-) create mode 100644 prisma/migrations/20241016110303_add_v2_migration_flag_to_user/migration.sql diff --git a/prisma/migrations/20241016110303_add_v2_migration_flag_to_user/migration.sql b/prisma/migrations/20241016110303_add_v2_migration_flag_to_user/migration.sql new file mode 100644 index 00000000..78149420 --- /dev/null +++ b/prisma/migrations/20241016110303_add_v2_migration_flag_to_user/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "migratedFromV2" BOOL; diff --git a/prisma/schema/schema.prisma b/prisma/schema/schema.prisma index 7cb5db2a..105617b4 100644 --- a/prisma/schema/schema.prisma +++ b/prisma/schema/schema.prisma @@ -26,6 +26,7 @@ model User { exerciseSplits ExerciseSplit[] mesocycles Mesocycle[] workouts Workout[] + migratedFromV2 Boolean? } model Account { diff --git a/src/lib/trpc/routes/users.ts b/src/lib/trpc/routes/users.ts index f4ab677e..e5bdfccd 100644 --- a/src/lib/trpc/routes/users.ts +++ b/src/lib/trpc/routes/users.ts @@ -26,12 +26,16 @@ function toPascalCase(text: V2MuscleGroup) { async function getPrismaAndMongoUser(userId: string) { const prismaUser = await prisma.user.findUnique({ where: { id: userId }, - select: { email: true, accounts: { select: { providerAccountId: true } } } + select: { email: true, accounts: { select: { providerAccountId: true } }, migratedFromV2: true } }); if (!prismaUser) { throw new TRPCError({ message: 'User not found in current database', code: 'BAD_REQUEST' }); } + if (prismaUser.migratedFromV2) { + throw new TRPCError({ message: 'Migration has already been performed', code: 'CONFLICT' }); + } + const client = await clientPromise; const mongoUser = await client.db().collection('users').findOne({ email: prismaUser?.email }); if (!mongoUser) { @@ -451,6 +455,8 @@ export const users = t.router({ }) }); + const updateUser = prisma.user.update({ where: { id: ctx.userId }, data: { migratedFromV2: true } }); + await prisma.$transaction([ exerciseSplitCreate, exerciseSplitDayCreate, @@ -463,7 +469,8 @@ export const users = t.router({ workoutExerciseSetCreate, workoutOfMesocycleCreate, restDaysCreate, - restWorkoutsOfMesocycle + restWorkoutsOfMesocycle, + updateUser ]); }) }); diff --git a/src/lib/zodSchemas/index.ts b/src/lib/zodSchemas/index.ts index 4b869689..e49a0e89 100644 --- a/src/lib/zodSchemas/index.ts +++ b/src/lib/zodSchemas/index.ts @@ -26,7 +26,7 @@ export const MesocycleExerciseSplitDayScalarFieldEnumSchema = z.enum(['id','name export const MesocycleExerciseTemplateScalarFieldEnumSchema = z.enum(['id','name','exerciseIndex','targetMuscleGroup','customMuscleGroup','bodyweightFraction','sets','setType','repRangeStart','repRangeEnd','changeType','changeAmount','note','mesocycleExerciseSplitDayId','overloadPercentage','lastSetToFailure','forceRIRMatching','minimumWeightChange']); -export const UserScalarFieldEnumSchema = z.enum(['id','name','email','emailVerified','image','createdAt','updatedAt']); +export const UserScalarFieldEnumSchema = z.enum(['id','name','email','emailVerified','image','createdAt','updatedAt','migratedFromV2']); export const AccountScalarFieldEnumSchema = z.enum(['userId','type','provider','providerAccountId','refresh_token','access_token','expires_at','token_type','scope','id_token','session_state','createdAt','updatedAt']); @@ -206,6 +206,7 @@ export const UserSchema = z.object({ image: z.string().nullable(), createdAt: z.coerce.date(), updatedAt: z.coerce.date(), + migratedFromV2: z.boolean().nullable(), }) export type User = z.infer @@ -616,6 +617,7 @@ export const UserSelectSchema: z.ZodType = z.object({ image: z.boolean().optional(), createdAt: z.boolean().optional(), updatedAt: z.boolean().optional(), + migratedFromV2: z.boolean().optional(), accounts: z.union([z.boolean(),z.lazy(() => AccountFindManyArgsSchema)]).optional(), sessions: z.union([z.boolean(),z.lazy(() => SessionFindManyArgsSchema)]).optional(), exerciseSplits: z.union([z.boolean(),z.lazy(() => ExerciseSplitFindManyArgsSchema)]).optional(), @@ -1431,6 +1433,7 @@ export const UserWhereInputSchema: z.ZodType = z.object({ image: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), createdAt: z.union([ z.lazy(() => DateTimeFilterSchema),z.coerce.date() ]).optional(), updatedAt: z.union([ z.lazy(() => DateTimeFilterSchema),z.coerce.date() ]).optional(), + migratedFromV2: z.union([ z.lazy(() => BoolNullableFilterSchema),z.boolean() ]).optional().nullable(), accounts: z.lazy(() => AccountListRelationFilterSchema).optional(), sessions: z.lazy(() => SessionListRelationFilterSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitListRelationFilterSchema).optional(), @@ -1446,6 +1449,7 @@ export const UserOrderByWithRelationInputSchema: z.ZodType SortOrderSchema),z.lazy(() => SortOrderInputSchema) ]).optional(), createdAt: z.lazy(() => SortOrderSchema).optional(), updatedAt: z.lazy(() => SortOrderSchema).optional(), + migratedFromV2: z.union([ z.lazy(() => SortOrderSchema),z.lazy(() => SortOrderInputSchema) ]).optional(), accounts: z.lazy(() => AccountOrderByRelationAggregateInputSchema).optional(), sessions: z.lazy(() => SessionOrderByRelationAggregateInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitOrderByRelationAggregateInputSchema).optional(), @@ -1476,6 +1480,7 @@ export const UserWhereUniqueInputSchema: z.ZodType image: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), createdAt: z.union([ z.lazy(() => DateTimeFilterSchema),z.coerce.date() ]).optional(), updatedAt: z.union([ z.lazy(() => DateTimeFilterSchema),z.coerce.date() ]).optional(), + migratedFromV2: z.union([ z.lazy(() => BoolNullableFilterSchema),z.boolean() ]).optional().nullable(), accounts: z.lazy(() => AccountListRelationFilterSchema).optional(), sessions: z.lazy(() => SessionListRelationFilterSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitListRelationFilterSchema).optional(), @@ -1491,6 +1496,7 @@ export const UserOrderByWithAggregationInputSchema: z.ZodType SortOrderSchema),z.lazy(() => SortOrderInputSchema) ]).optional(), createdAt: z.lazy(() => SortOrderSchema).optional(), updatedAt: z.lazy(() => SortOrderSchema).optional(), + migratedFromV2: z.union([ z.lazy(() => SortOrderSchema),z.lazy(() => SortOrderInputSchema) ]).optional(), _count: z.lazy(() => UserCountOrderByAggregateInputSchema).optional(), _max: z.lazy(() => UserMaxOrderByAggregateInputSchema).optional(), _min: z.lazy(() => UserMinOrderByAggregateInputSchema).optional() @@ -1507,6 +1513,7 @@ export const UserScalarWhereWithAggregatesInputSchema: z.ZodType StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), createdAt: z.union([ z.lazy(() => DateTimeWithAggregatesFilterSchema),z.coerce.date() ]).optional(), updatedAt: z.union([ z.lazy(() => DateTimeWithAggregatesFilterSchema),z.coerce.date() ]).optional(), + migratedFromV2: z.union([ z.lazy(() => BoolNullableWithAggregatesFilterSchema),z.boolean() ]).optional().nullable(), }).strict(); export const AccountWhereInputSchema: z.ZodType = z.object({ @@ -2715,6 +2722,7 @@ export const UserCreateInputSchema: z.ZodType = z.object image: z.string().optional().nullable(), createdAt: z.coerce.date().optional(), updatedAt: z.coerce.date().optional(), + migratedFromV2: z.boolean().optional().nullable(), accounts: z.lazy(() => AccountCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitCreateNestedManyWithoutUserInputSchema).optional(), @@ -2730,6 +2738,7 @@ export const UserUncheckedCreateInputSchema: z.ZodType AccountUncheckedCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedCreateNestedManyWithoutUserInputSchema).optional(), @@ -2745,6 +2754,7 @@ export const UserUpdateInputSchema: z.ZodType = z.object image: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUpdateManyWithoutUserNestedInputSchema).optional(), @@ -2760,6 +2770,7 @@ export const UserUncheckedUpdateInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), @@ -2774,7 +2785,8 @@ export const UserCreateManyInputSchema: z.ZodType = emailVerified: z.coerce.date().optional().nullable(), image: z.string().optional().nullable(), createdAt: z.coerce.date().optional(), - updatedAt: z.coerce.date().optional() + updatedAt: z.coerce.date().optional(), + migratedFromV2: z.boolean().optional().nullable() }).strict(); export const UserUpdateManyMutationInputSchema: z.ZodType = z.object({ @@ -2785,6 +2797,7 @@ export const UserUpdateManyMutationInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const UserUncheckedUpdateManyInputSchema: z.ZodType = z.object({ @@ -2795,6 +2808,7 @@ export const UserUncheckedUpdateManyInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const AccountCreateInputSchema: z.ZodType = z.object({ @@ -4138,7 +4152,8 @@ export const UserCountOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), image: z.lazy(() => SortOrderSchema).optional(), createdAt: z.lazy(() => SortOrderSchema).optional(), - updatedAt: z.lazy(() => SortOrderSchema).optional() + updatedAt: z.lazy(() => SortOrderSchema).optional(), + migratedFromV2: z.lazy(() => SortOrderSchema).optional() }).strict(); export const UserMaxOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -4148,7 +4163,8 @@ export const UserMaxOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), image: z.lazy(() => SortOrderSchema).optional(), createdAt: z.lazy(() => SortOrderSchema).optional(), - updatedAt: z.lazy(() => SortOrderSchema).optional() + updatedAt: z.lazy(() => SortOrderSchema).optional(), + migratedFromV2: z.lazy(() => SortOrderSchema).optional() }).strict(); export const UserMinOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -4158,7 +4174,8 @@ export const UserMinOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), image: z.lazy(() => SortOrderSchema).optional(), createdAt: z.lazy(() => SortOrderSchema).optional(), - updatedAt: z.lazy(() => SortOrderSchema).optional() + updatedAt: z.lazy(() => SortOrderSchema).optional(), + migratedFromV2: z.lazy(() => SortOrderSchema).optional() }).strict(); export const DateTimeWithAggregatesFilterSchema: z.ZodType = z.object({ @@ -5897,6 +5914,7 @@ export const UserCreateWithoutExerciseSplitsInputSchema: z.ZodType AccountCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionCreateNestedManyWithoutUserInputSchema).optional(), mesocycles: z.lazy(() => MesocycleCreateNestedManyWithoutUserInputSchema).optional(), @@ -5911,6 +5929,7 @@ export const UserUncheckedCreateWithoutExerciseSplitsInputSchema: z.ZodType AccountUncheckedCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedCreateNestedManyWithoutUserInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUncheckedCreateNestedManyWithoutUserInputSchema).optional(), @@ -6007,6 +6026,7 @@ export const UserUpdateWithoutExerciseSplitsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUpdateManyWithoutUserNestedInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUpdateManyWithoutUserNestedInputSchema).optional(), @@ -6021,6 +6041,7 @@ export const UserUncheckedUpdateWithoutExerciseSplitsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), @@ -6261,6 +6282,7 @@ export const UserCreateWithoutMesocyclesInputSchema: z.ZodType AccountCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitCreateNestedManyWithoutUserInputSchema).optional(), @@ -6275,6 +6297,7 @@ export const UserUncheckedCreateWithoutMesocyclesInputSchema: z.ZodType AccountUncheckedCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedCreateNestedManyWithoutUserInputSchema).optional(), @@ -6402,6 +6425,7 @@ export const UserUpdateWithoutMesocyclesInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUpdateManyWithoutUserNestedInputSchema).optional(), @@ -6416,6 +6440,7 @@ export const UserUncheckedUpdateWithoutMesocyclesInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), @@ -7114,6 +7139,7 @@ export const UserCreateWithoutAccountsInputSchema: z.ZodType SessionCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitCreateNestedManyWithoutUserInputSchema).optional(), mesocycles: z.lazy(() => MesocycleCreateNestedManyWithoutUserInputSchema).optional(), @@ -7128,6 +7154,7 @@ export const UserUncheckedCreateWithoutAccountsInputSchema: z.ZodType SessionUncheckedCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedCreateNestedManyWithoutUserInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUncheckedCreateNestedManyWithoutUserInputSchema).optional(), @@ -7158,6 +7185,7 @@ export const UserUpdateWithoutAccountsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), sessions: z.lazy(() => SessionUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUpdateManyWithoutUserNestedInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUpdateManyWithoutUserNestedInputSchema).optional(), @@ -7172,6 +7200,7 @@ export const UserUncheckedUpdateWithoutAccountsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), sessions: z.lazy(() => SessionUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), @@ -7186,6 +7215,7 @@ export const UserCreateWithoutSessionsInputSchema: z.ZodType AccountCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitCreateNestedManyWithoutUserInputSchema).optional(), mesocycles: z.lazy(() => MesocycleCreateNestedManyWithoutUserInputSchema).optional(), @@ -7200,6 +7230,7 @@ export const UserUncheckedCreateWithoutSessionsInputSchema: z.ZodType AccountUncheckedCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedCreateNestedManyWithoutUserInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUncheckedCreateNestedManyWithoutUserInputSchema).optional(), @@ -7230,6 +7261,7 @@ export const UserUpdateWithoutSessionsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUpdateManyWithoutUserNestedInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUpdateManyWithoutUserNestedInputSchema).optional(), @@ -7244,6 +7276,7 @@ export const UserUncheckedUpdateWithoutSessionsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), mesocycles: z.lazy(() => MesocycleUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), @@ -7386,6 +7419,7 @@ export const UserCreateWithoutWorkoutsInputSchema: z.ZodType AccountCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitCreateNestedManyWithoutUserInputSchema).optional(), @@ -7400,6 +7434,7 @@ export const UserUncheckedCreateWithoutWorkoutsInputSchema: z.ZodType AccountUncheckedCreateNestedManyWithoutUserInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedCreateNestedManyWithoutUserInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedCreateNestedManyWithoutUserInputSchema).optional(), @@ -7499,6 +7534,7 @@ export const UserUpdateWithoutWorkoutsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUpdateManyWithoutUserNestedInputSchema).optional(), @@ -7513,6 +7549,7 @@ export const UserUncheckedUpdateWithoutWorkoutsInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), updatedAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), + migratedFromV2: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), accounts: z.lazy(() => AccountUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), sessions: z.lazy(() => SessionUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), exerciseSplits: z.lazy(() => ExerciseSplitUncheckedUpdateManyWithoutUserNestedInputSchema).optional(), diff --git a/src/routes/profile/+page.svelte b/src/routes/profile/+page.svelte index 1fbee8a9..37272906 100644 --- a/src/routes/profile/+page.svelte +++ b/src/routes/profile/+page.svelte @@ -11,6 +11,7 @@ import { Input } from '$lib/components/ui/input/index.js'; import { Label } from '$lib/components/ui/label/index.js'; import Separator from '$lib/components/ui/separator/separator.svelte'; + import { goto } from '$app/navigation'; let { data } = $props(); let migratingToV2 = $state(false); @@ -25,6 +26,7 @@ migratingToV2 = true; toast.warning("Don't close this window or reload the page"); await trpc().users.migrateFromV2.mutate({ bodyweight, duration }); + await goto('/'); migratingToV2 = false; toast.success('Migration completed successfully'); } catch (error) { @@ -52,56 +54,58 @@ {#await data.V2Counts} {:then V2Counts} - - - V2 migration - Get all your data from V2 into V3 - - -

- {#if typeof V2Counts === 'string'} - {V2Counts} - {:else} - Email: {V2Counts.emailId}
- Mesocycles: {V2Counts.mesocyclesCount}
- Mesocycle Templates: {V2Counts.mesocycleTemplatesCount}
- Workouts: {V2Counts.workoutsCount} - {/if} -

+ {#if V2Counts !== 'Migration has already been performed'} + + + V2 migration + Get all your data from V2 into V3 + + +

+ {#if typeof V2Counts === 'string'} + {V2Counts} + {:else} + Email: {V2Counts.emailId}
+ Mesocycles: {V2Counts.mesocyclesCount}
+ Mesocycle Templates: {V2Counts.mesocycleTemplatesCount}
+ Workouts: {V2Counts.workoutsCount} + {/if} +

- + -
-

Enter averages to fill-in new V3 data

-
- - -
-
- - -
-
-
- - - -
+
+

Enter averages to fill-in new V3 data

+
+ + +
+
+ + +
+
+
+ + + +
+ {/if} {/await}