tasks
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
This commit is contained in:
parent
7070be9953
commit
9c132174c5
1 changed files with 5 additions and 9 deletions
|
|
@ -16,13 +16,6 @@ class TasksSeederTask with cron_task.Task {
|
||||||
print('Seeding initial user tasks...');
|
print('Seeding initial user tasks...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if tasks already exist
|
|
||||||
final existingTasks = await _db.taskDao.getAllUserTasks();
|
|
||||||
if (existingTasks.isNotEmpty) {
|
|
||||||
print('Tasks already exist, skipping seeding');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final weekFromNow = now.add(const Duration(days: 7));
|
final weekFromNow = now.add(const Duration(days: 7));
|
||||||
|
|
||||||
|
|
@ -203,9 +196,11 @@ class TasksSeederTask with cron_task.Task {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Convert UserTaskModel to UserTasksCompanion and insert
|
// Convert UserTaskModel to UserTasksCompanion and insert
|
||||||
|
// Используем InsertMode.insertOrIgnore для автоматического игнорирования дубликатов через ON CONFLICT
|
||||||
for (final taskModel in tasks) {
|
for (final taskModel in tasks) {
|
||||||
final rewardsJson = taskModel.rewards.map((r) => r.toJson()).toList();
|
final rewardsJson = taskModel.rewards.map((r) => r.toJson()).toList();
|
||||||
await _db.taskDao.createUserTask(
|
|
||||||
|
await _db.into(_db.userTasks).insert(
|
||||||
UserTasksCompanion.insert(
|
UserTasksCompanion.insert(
|
||||||
title: taskModel.title,
|
title: taskModel.title,
|
||||||
description: taskModel.description,
|
description: taskModel.description,
|
||||||
|
|
@ -221,10 +216,11 @@ class TasksSeederTask with cron_task.Task {
|
||||||
tags: Value(taskModel.tags),
|
tags: Value(taskModel.tags),
|
||||||
imageUrl: Value(taskModel.imageUrl),
|
imageUrl: Value(taskModel.imageUrl),
|
||||||
),
|
),
|
||||||
|
mode: InsertMode.insertOrIgnore, // ON CONFLICT DO NOTHING
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
print('Successfully seeded ${tasks.length} user tasks');
|
print('Successfully seeded ${tasks.length} user tasks (duplicates ignored)');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error seeding tasks: $e');
|
print('Error seeding tasks: $e');
|
||||||
rethrow;
|
rethrow;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue