@nina-protocol/nina-db 0.0.67 → 0.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/migrations/20231116215117_add_tags.js +0 -1
- package/dist/migrations/20240304143626_tags_releases.js +32 -0
- package/dist/models/Tag.js +4 -2
- package/dist/models/TagsReleases.js +17 -0
- package/package.json +1 -1
- package/src/migrations/20231116215117_add_tags.js +0 -1
- package/src/migrations/20240304143626_tags_releases.js +2 -0
- package/src/models/Tag.js +5 -2
- package/src/models/TagsReleases.js +20 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param { import("knex").Knex } knex
|
|
3
|
+
* @returns { Promise<void> }
|
|
4
|
+
*/
|
|
5
|
+
export const up = function (knex) {
|
|
6
|
+
return Promise.all([
|
|
7
|
+
knex.schema.createTable('tags_releases', table => {
|
|
8
|
+
table.primary(['tagId', 'releaseId']);
|
|
9
|
+
table.integer('releaseId')
|
|
10
|
+
.unsigned()
|
|
11
|
+
.references('id')
|
|
12
|
+
.inTable('releases')
|
|
13
|
+
.onDelete('CASCADE')
|
|
14
|
+
.index();
|
|
15
|
+
table.integer('tagId')
|
|
16
|
+
.unsigned()
|
|
17
|
+
.references('id')
|
|
18
|
+
.inTable('tags')
|
|
19
|
+
.onDelete('CASCADE')
|
|
20
|
+
.index();
|
|
21
|
+
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
22
|
+
table.timestamp('updated_at').defaultTo(knex.fn.now());
|
|
23
|
+
}),
|
|
24
|
+
]);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @param { import("knex").Knex } knex
|
|
28
|
+
* @returns { Promise<void> }
|
|
29
|
+
*/
|
|
30
|
+
export const down = function (knex) {
|
|
31
|
+
return knex.schema.dropTableIfExists('tags_releases');
|
|
32
|
+
};
|
package/dist/models/Tag.js
CHANGED
|
@@ -10,10 +10,12 @@ export default class Tag extends Model {
|
|
|
10
10
|
value: { type: 'string' },
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
|
+
static sanitizeValue = (value) => value.toLowerCase().replace('#', '').replace(',', '');
|
|
13
14
|
static findOrCreate = async (value) => {
|
|
14
|
-
|
|
15
|
+
const sanitizedValue = sanitizeValue(value);
|
|
16
|
+
let tag = await Tag.query().where('value', sanitizedValue).first();
|
|
15
17
|
if (!tag) {
|
|
16
|
-
tag = await Tag.query().insert({ value });
|
|
18
|
+
tag = await Tag.query().insert({ value: sanitizedValue });
|
|
17
19
|
}
|
|
18
20
|
return tag;
|
|
19
21
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
export default class TagsRelease extends Model {
|
|
3
|
+
static tableName = 'tags_releases';
|
|
4
|
+
$beforeUpdate() {
|
|
5
|
+
this.updatedAt = new Date().toISOString();
|
|
6
|
+
}
|
|
7
|
+
static jsonSchema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
required: ['tagId', 'releaseId', 'createdAt', 'updatedAt'],
|
|
10
|
+
properties: {
|
|
11
|
+
tagId: { type: 'integer' },
|
|
12
|
+
releaseId: { type: 'integer' },
|
|
13
|
+
createdAt: { type: 'string' },
|
|
14
|
+
updatedAt: { type: 'string' },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
package/package.json
CHANGED
package/src/models/Tag.js
CHANGED
|
@@ -12,10 +12,13 @@ export default class Tag extends Model {
|
|
|
12
12
|
},
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
static sanitizeValue = (value) => value.toLowerCase().replace('#', '').replace(',', '');
|
|
16
|
+
|
|
15
17
|
static findOrCreate = async (value) => {
|
|
16
|
-
|
|
18
|
+
const sanitizedValue = sanitizeValue(value);
|
|
19
|
+
let tag = await Tag.query().where('value', sanitizedValue).first();
|
|
17
20
|
if (!tag) {
|
|
18
|
-
tag = await Tag.query().insert({ value });
|
|
21
|
+
tag = await Tag.query().insert({ value: sanitizedValue });
|
|
19
22
|
}
|
|
20
23
|
return tag;
|
|
21
24
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
|
|
3
|
+
export default class TagsRelease extends Model {
|
|
4
|
+
static tableName = 'tags_releases';
|
|
5
|
+
|
|
6
|
+
$beforeUpdate() {
|
|
7
|
+
this.updatedAt = new Date().toISOString();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static jsonSchema = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
required: ['tagId', 'releaseId', 'createdAt', 'updatedAt'],
|
|
13
|
+
properties: {
|
|
14
|
+
tagId: { type: 'integer' },
|
|
15
|
+
releaseId: { type: 'integer' },
|
|
16
|
+
createdAt: { type: 'string' },
|
|
17
|
+
updatedAt: { type: 'string' },
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
}
|