It seems that SQLite doesn't convert automatically strings to integer, whenn I try to migrate the databse on sqlite I recive this error:
insert into `gb_schema_migrations` (`changes`, `id`, `model`, `sql_up`) values ('[{"type":"TYPE_ADDED","path":{"type":"Item"}}]', '1574260178473', '
type Item {
id: ID!
title: String!
}
', 'create table `item` (`id` integer not null primary key autoincrement, `title` text);') - SQLITE_CONSTRAINT: UNIQUE constraint failed: gb_schema_migrations.id
What am I doing:
const knex = Knex({
client: "sqlite3",
connection: { filename: ":memory:" }
});
const dir = tmp.dirSync();
const migrater = new UpdateDatabaseIfChanges(knex, dir.name);
await migrater.init(this.schema.getSchemaText());
My workaround packages/graphql-migrations/src/migrations/KnexMigrationManager.ts
public async createMigration(migration: SchemaMigration): Promise<void> {
try {
// convert id to integer
(migration as any).id = parseInt(migration.id);
// tslint:disable-next-line: await-promise
await this.db.table(this.tables.migrations).insert(migration);
} catch (err) {
handleError(err);
}
return Promise.resolve();
}
Graphback: 0.10.0-dev2
@b1zzu Thank you so much. Please use CreateDatabase strategy for the moment.
We are going to address this issue.
@wtrocki do you mean the old method?
@wtrocki do you mean the old method?
@b1zzu
https://github.com/aerogear/graphback/tree/master/packages/graphql-migrations#drop-and-recreate-database-every-time
const databaseInitializationStrategy = new DropCreateDatabaseAlways('pg', db);
You can use DropCreateDatabase initialization strategy which uses the old engine to create the database talbes, relationships etc.
The DropCreateDatabaseAlways works fine
@b1zzu https://github.com/aerogear/graphback/pull/503 should have fixed this now.
Currently released: https://app.circleci.com/jobs/github/aerogear/graphback/1532
Thanks, @craicoverflow !!.. but I don't think I will going to use it for now in testx because I feel that DropCreateDatabaseAlways is more appropriate given the fact that it doesn't require a diretory where to store the migrations data
Most helpful comment
@b1zzu
https://github.com/aerogear/graphback/tree/master/packages/graphql-migrations#drop-and-recreate-database-every-time
You can use
DropCreateDatabaseinitialization strategy which uses the old engine to create the database talbes, relationships etc.