@nina-protocol/nina-db 0.0.118 → 0.0.119
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/20260107000000_add_tags_posts.js +30 -0
- package/dist/models/Post.js +13 -0
- package/dist/models/Tag.js +13 -0
- package/dist/models/TagsPosts.js +17 -0
- package/package.json +1 -1
- package/src/migrations/20260107000000_add_tags_posts.js +31 -0
- package/src/models/Post.js +13 -0
- package/src/models/Tag.js +13 -0
- package/src/models/TagsPosts.js +20 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param { import("knex").Knex } knex
|
|
3
|
+
* @returns { Promise<void> }
|
|
4
|
+
*/
|
|
5
|
+
export const up = function (knex) {
|
|
6
|
+
return knex.schema.createTable('tags_posts', table => {
|
|
7
|
+
table.primary(['tagId', 'postId']);
|
|
8
|
+
table.integer('postId')
|
|
9
|
+
.unsigned()
|
|
10
|
+
.references('id')
|
|
11
|
+
.inTable('posts')
|
|
12
|
+
.onDelete('CASCADE')
|
|
13
|
+
.index();
|
|
14
|
+
table.integer('tagId')
|
|
15
|
+
.unsigned()
|
|
16
|
+
.references('id')
|
|
17
|
+
.inTable('tags')
|
|
18
|
+
.onDelete('CASCADE')
|
|
19
|
+
.index();
|
|
20
|
+
table.timestamp('createdAt').defaultTo(knex.fn.now());
|
|
21
|
+
table.timestamp('updatedAt').defaultTo(knex.fn.now());
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @param { import("knex").Knex } knex
|
|
26
|
+
* @returns { Promise<void> }
|
|
27
|
+
*/
|
|
28
|
+
export const down = function (knex) {
|
|
29
|
+
return knex.schema.dropTableIfExists('tags_posts');
|
|
30
|
+
};
|
package/dist/models/Post.js
CHANGED
|
@@ -3,6 +3,7 @@ import { stripHtmlIfNeeded } from '../utils/index.js';
|
|
|
3
3
|
import Account from './Account.js';
|
|
4
4
|
import Hub from './Hub.js';
|
|
5
5
|
import Release from './Release.js';
|
|
6
|
+
import Tag from './Tag.js';
|
|
6
7
|
class Post extends Model {
|
|
7
8
|
static get tableName() {
|
|
8
9
|
return 'posts';
|
|
@@ -79,6 +80,18 @@ class Post extends Model {
|
|
|
79
80
|
to: 'releases.id',
|
|
80
81
|
},
|
|
81
82
|
},
|
|
83
|
+
tags: {
|
|
84
|
+
relation: Model.ManyToManyRelation,
|
|
85
|
+
modelClass: Tag,
|
|
86
|
+
join: {
|
|
87
|
+
from: 'posts.id',
|
|
88
|
+
through: {
|
|
89
|
+
from: 'tags_posts.postId',
|
|
90
|
+
to: 'tags_posts.tagId',
|
|
91
|
+
},
|
|
92
|
+
to: 'tags.id',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
82
95
|
});
|
|
83
96
|
}
|
|
84
97
|
export default Post;
|
package/dist/models/Tag.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Model } from 'objection';
|
|
2
2
|
import Release from './Release.js';
|
|
3
|
+
import Post from './Post.js';
|
|
3
4
|
export default class Tag extends Model {
|
|
4
5
|
static tableName = 'tags';
|
|
5
6
|
static idColumn = 'id';
|
|
@@ -35,5 +36,17 @@ export default class Tag extends Model {
|
|
|
35
36
|
to: 'releases.id',
|
|
36
37
|
},
|
|
37
38
|
},
|
|
39
|
+
posts: {
|
|
40
|
+
relation: Model.ManyToManyRelation,
|
|
41
|
+
modelClass: Post,
|
|
42
|
+
join: {
|
|
43
|
+
from: 'tags.id',
|
|
44
|
+
through: {
|
|
45
|
+
from: 'tags_posts.tagId',
|
|
46
|
+
to: 'tags_posts.postId',
|
|
47
|
+
},
|
|
48
|
+
to: 'posts.id',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
38
51
|
});
|
|
39
52
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
export default class TagsPosts extends Model {
|
|
3
|
+
static tableName = 'tags_posts';
|
|
4
|
+
$beforeUpdate() {
|
|
5
|
+
this.updatedAt = new Date().toISOString();
|
|
6
|
+
}
|
|
7
|
+
static jsonSchema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
required: ['tagId', 'postId'],
|
|
10
|
+
properties: {
|
|
11
|
+
tagId: { type: 'integer' },
|
|
12
|
+
postId: { type: 'integer' },
|
|
13
|
+
createdAt: { type: 'string' },
|
|
14
|
+
updatedAt: { type: 'string' },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param { import("knex").Knex } knex
|
|
3
|
+
* @returns { Promise<void> }
|
|
4
|
+
*/
|
|
5
|
+
export const up = function (knex) {
|
|
6
|
+
return knex.schema.createTable('tags_posts', table => {
|
|
7
|
+
table.primary(['tagId', 'postId']);
|
|
8
|
+
table.integer('postId')
|
|
9
|
+
.unsigned()
|
|
10
|
+
.references('id')
|
|
11
|
+
.inTable('posts')
|
|
12
|
+
.onDelete('CASCADE')
|
|
13
|
+
.index();
|
|
14
|
+
table.integer('tagId')
|
|
15
|
+
.unsigned()
|
|
16
|
+
.references('id')
|
|
17
|
+
.inTable('tags')
|
|
18
|
+
.onDelete('CASCADE')
|
|
19
|
+
.index();
|
|
20
|
+
table.timestamp('createdAt').defaultTo(knex.fn.now());
|
|
21
|
+
table.timestamp('updatedAt').defaultTo(knex.fn.now());
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param { import("knex").Knex } knex
|
|
27
|
+
* @returns { Promise<void> }
|
|
28
|
+
*/
|
|
29
|
+
export const down = function (knex) {
|
|
30
|
+
return knex.schema.dropTableIfExists('tags_posts');
|
|
31
|
+
};
|
package/src/models/Post.js
CHANGED
|
@@ -3,6 +3,7 @@ import { stripHtmlIfNeeded } from '../utils/index.js';
|
|
|
3
3
|
import Account from './Account.js';
|
|
4
4
|
import Hub from './Hub.js';
|
|
5
5
|
import Release from './Release.js';
|
|
6
|
+
import Tag from './Tag.js';
|
|
6
7
|
|
|
7
8
|
class Post extends Model {
|
|
8
9
|
static get tableName() {
|
|
@@ -85,6 +86,18 @@ class Post extends Model {
|
|
|
85
86
|
to: 'releases.id',
|
|
86
87
|
},
|
|
87
88
|
},
|
|
89
|
+
tags: {
|
|
90
|
+
relation: Model.ManyToManyRelation,
|
|
91
|
+
modelClass: Tag,
|
|
92
|
+
join: {
|
|
93
|
+
from: 'posts.id',
|
|
94
|
+
through: {
|
|
95
|
+
from: 'tags_posts.postId',
|
|
96
|
+
to: 'tags_posts.tagId',
|
|
97
|
+
},
|
|
98
|
+
to: 'tags.id',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
88
101
|
})
|
|
89
102
|
}
|
|
90
103
|
|
package/src/models/Tag.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Model } from 'objection';
|
|
2
2
|
import Release from './Release.js';
|
|
3
|
+
import Post from './Post.js';
|
|
3
4
|
|
|
4
5
|
export default class Tag extends Model {
|
|
5
6
|
static tableName = 'tags';
|
|
@@ -40,5 +41,17 @@ export default class Tag extends Model {
|
|
|
40
41
|
to: 'releases.id',
|
|
41
42
|
},
|
|
42
43
|
},
|
|
44
|
+
posts: {
|
|
45
|
+
relation: Model.ManyToManyRelation,
|
|
46
|
+
modelClass: Post,
|
|
47
|
+
join: {
|
|
48
|
+
from: 'tags.id',
|
|
49
|
+
through: {
|
|
50
|
+
from: 'tags_posts.tagId',
|
|
51
|
+
to: 'tags_posts.postId',
|
|
52
|
+
},
|
|
53
|
+
to: 'posts.id',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
43
56
|
});
|
|
44
57
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
|
|
3
|
+
export default class TagsPosts extends Model {
|
|
4
|
+
static tableName = 'tags_posts';
|
|
5
|
+
|
|
6
|
+
$beforeUpdate() {
|
|
7
|
+
this.updatedAt = new Date().toISOString();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static jsonSchema = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
required: ['tagId', 'postId'],
|
|
13
|
+
properties: {
|
|
14
|
+
tagId: { type: 'integer' },
|
|
15
|
+
postId: { type: 'integer' },
|
|
16
|
+
createdAt: { type: 'string' },
|
|
17
|
+
updatedAt: { type: 'string' },
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
}
|