Я настраиваю базу данных PostgreSQL для моего сервера Aqueduct. Я создал пользователя и базу данных с psql
:
CREATE DATABASE words;
CREATE USER words_user WITH createdb;
ALTER USER words_user WITH password 'password';
GRANT all ON database words TO words_user;
Мой класс модели
import 'package:demo/demo.dart';
class Word extends ManagedObject<_Word> implements _Word {
}
class _Word {
@primaryKey
int id;
@Column(unique: true)
String word;
@Column()
String info;
}
Я сгенерировал файл миграции с
aqueduct db generate
, что:
import 'dart:async';
import 'package:aqueduct/aqueduct.dart';
class Migration1 extends Migration {
@override
Future upgrade() async {
database.createTable(SchemaTable("_Word", [
SchemaColumn("id", ManagedPropertyType.bigInteger,
isPrimaryKey: true,
autoincrement: true,
isIndexed: false,
isNullable: false,
isUnique: false),
SchemaColumn("word", ManagedPropertyType.string,
isPrimaryKey: false,
autoincrement: false,
isIndexed: false,
isNullable: false,
isUnique: true),
SchemaColumn("info", ManagedPropertyType.string,
isPrimaryKey: false,
autoincrement: false,
isIndexed: false,
isNullable: false,
isUnique: false)
]));
}
@override
Future downgrade() async {}
@override
Future seed() async {
final rows = [
{'word': 'horse', 'info': 'large animal you can ride'},
{'word': 'cow', 'info': 'large animal you can milk'},
{'word': 'camel', 'info': 'large animal with humps'},
{'word': 'sheep', 'info': 'small animal with wool'},
{'word': 'goat', 'info': 'small animal with horns'},
];
for (final row in rows) {
await database.store.execute(
"INSERT INTO _Word (word, info) VALUES (@word, @info)",
substitutionValues: {
"word": row['word'],
"info": row['info'],
});
}
}
}
Но теперь, когда я пытаюсь применить миграцию с помощью
aqueduct db upgrade --connect postgres:password@localhost:5432/words
Я получаю ошибку:
*** Произошла ошибка при подключении к базе данных 'null: null @: 0 / null'. Причина: не удалось подключиться к базе данных.
Я отследил это сообщение об ошибке как здесь в исходном коде.