Skip to content

Instantly share code, notes, and snippets.

@drexel-ue
Last active July 16, 2019 23:54
Show Gist options
  • Select an option

  • Save drexel-ue/f338a9a2e31796fe24cc5c61fb7f944f to your computer and use it in GitHub Desktop.

Select an option

Save drexel-ue/f338a9a2e31796fe24cc5c61fb7f944f to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:aqueduct/aqueduct.dart';
import 'package:faker/faker.dart';
import 'package:uuid/uuid.dart';
class Migration9 extends Migration {
@override
Future upgrade() async {}
@override
Future downgrade() async {}
@override
Future seed() async {
const faker = Faker();
const categories = [
'music',
'geography',
'black girl magic',
'black history',
'film',
'sports'
];
for (var i = 0; i < 30; i++) {
categories.shuffle();
final category = categories.first;
final questionIdentifier = Uuid().v4();
const questionSql = '''
insert into _question (identifier, body, category, createdat)
Values (@identifier, @body, @category, @createdat)
''';
await store.execute(questionSql, substitutionValues: {
'identifier': questionIdentifier,
'body': faker.lorem.sentence(),
'category': category,
'createdat': DateTime.now(),
});
const answerSql = '''
insert into _answer (identifier, body, category, createdat, question_identifier)
Values (@identifier, @body, @category, @createdat, @question_identifier)
''';
final answerIdentifier = Uuid().v4();
await store.execute(answerSql, substitutionValues: {
'identifier': answerIdentifier,
'body': faker.lorem.sentence(),
'category': category,
'createdat': DateTime.now(),
'question_identifier': questionIdentifier,
});
for (var i = 0; i < 4; i++) {
const answerSql = '''
insert into _answer (identifier, body, category, createdat)
Values (@identifier, @body, @category, @createdat)
''';
final answerIdentifier = Uuid().v4();
await store.execute(answerSql, substitutionValues: {
'identifier': answerIdentifier,
'body': faker.lorem.sentence(),
'category': category,
'createdat': DateTime.now(),
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment