Skip to content

Commit

Permalink
Fix DB rename feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-burlacu-software committed Jan 14, 2024
1 parent 5ec13a6 commit 08b2630
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stark-db",
"version": "1.3.3",
"version": "1.3.4",
"description": "Database engine based on SQLite.",
"bin": {
"stark-db": "./dist/src/index.js"
Expand Down
25 changes: 21 additions & 4 deletions src/services/DB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,36 @@ export class DB implements AsyncDisposable {
}

async set(arg: { user: User, DB: DBArg }): Promise<DBBase> {
const localDB = await this.get(arg);
const localDB = await this.get({
user: arg.user,
DB: { ID: arg.DB.ID }
});

ForbiddenError
.from(defineAbilityForDB(arg.user))
.throwUnlessCan(DBOp.Admin, localDB);

const previousName = localDB.name;

// Update the DB entry.
await localDB.save(arg.DB);

// Initialize the DB file object.
const localDBFile = new DBFile({
name: localDB.name,
name: previousName,
types: []
});
await localDBFile.save({ name: arg.DB.name, types: [] });

await localDB.save(arg.DB);
// Retry updating the file until it succeeds.
await retry(
async (_bail) => {
await localDBFile.save({ name: arg.DB.name, types: [] });
},
{
retries: 3,
minTimeout: DB_EXISTS_CHECK
}
);

return localDB;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"info": {
"description": "The Stark DB Server.",
"version": "1.3.2",
"version": "1.3.4",
"title": "Stark DB API",
"termsOfService": "",
"contact": {
Expand Down

0 comments on commit 08b2630

Please sign in to comment.