1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Server: Add unique constraint on name and owner ID of items table

In theory, the server enforces uniquness because when doing a PUT
operation it either creates the items if it doesn't exist, or overwrite
it. However, there's race condition that makes it possible for multiple
items with the same name being created per user. So we add this
constraint to ensure that any additional query would fail (which can be
recovered by repeating the request).
This commit is contained in:
Laurent Cozic 2021-10-30 10:37:56 +01:00
parent bb06e56a05
commit f7a18bac2a

View File

@ -0,0 +1,14 @@
import { Knex } from 'knex';
import { DbConnection } from '../db';
export async function up(db: DbConnection): Promise<any> {
await db.schema.alterTable('items', (table: Knex.CreateTableBuilder) => {
table.unique(['name', 'owner_id']);
});
}
export async function down(db: DbConnection): Promise<any> {
await db.schema.alterTable('items', (table: Knex.CreateTableBuilder) => {
table.dropUnique(['name', 'owner_id']);
});
}