@nina-protocol/nina-db 0.0.65 → 0.0.67

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/index.js CHANGED
@@ -24,6 +24,7 @@ export const Hub = Models.Hub;
24
24
  export const Post = Models.Post;
25
25
  export const Release = Models.Release;
26
26
  export const Subscription = Models.Subscription;
27
+ export const Tag = Models.Tag;
27
28
  export const Transaction = Models.Transaction;
28
29
  export const Verification = Models.Verification;
29
30
  export const config = knexConfig;
@@ -0,0 +1,31 @@
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.dropTable('tags_content'),
8
+ knex.schema.createTable('tags_releases', table => {
9
+ table.primary(['tagId', 'releaseId']);
10
+ table.integer('releaseId')
11
+ .unsigned()
12
+ .references('id')
13
+ .inTable('releases')
14
+ .onDelete('CASCADE')
15
+ .index();
16
+ table.integer('tagId')
17
+ .unsigned()
18
+ .references('id')
19
+ .inTable('tags')
20
+ .onDelete('CASCADE')
21
+ .index();
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_releases');
31
+ };
@@ -245,8 +245,8 @@ export default class Release extends Model {
245
245
  join: {
246
246
  from: 'releases.id',
247
247
  through: {
248
- from: 'tags_content.releaseId',
249
- to: 'tags_content.tagId',
248
+ from: 'tags_releases.releaseId',
249
+ to: 'tags_releases.tagId',
250
250
  },
251
251
  to: 'tags.id',
252
252
  },
@@ -1,4 +1,5 @@
1
1
  import { Model } from 'objection';
2
+ import Release from './Release.js';
2
3
  export default class Tag extends Model {
3
4
  static tableName = 'tags';
4
5
  static idColumn = 'id';
@@ -9,37 +10,25 @@ export default class Tag extends Model {
9
10
  value: { type: 'string' },
10
11
  },
11
12
  };
12
- async findOrCreate(value) {
13
+ static findOrCreate = async (value) => {
13
14
  let tag = await Tag.query().where('value', value).first();
14
15
  if (!tag) {
15
16
  tag = await Tag.query().insert({ value });
16
17
  }
17
18
  return tag;
18
- }
19
- async format() {
19
+ };
20
+ format = () => {
20
21
  delete this.id;
21
- }
22
+ };
22
23
  static relationMappings = () => ({
23
- posts: {
24
- relation: Model.ManyToManyRelation,
25
- modelClass: 'Post',
26
- join: {
27
- from: 'tags.id',
28
- through: {
29
- from: 'tags_content.tagId',
30
- to: 'tags_content.postId',
31
- },
32
- to: 'posts.id',
33
- },
34
- },
35
24
  releases: {
36
25
  relation: Model.ManyToManyRelation,
37
- modelClass: 'Release',
26
+ modelClass: Release,
38
27
  join: {
39
28
  from: 'tags.id',
40
29
  through: {
41
- from: 'tags_content.tagId',
42
- to: 'tags_content.releaseId',
30
+ from: 'tags_releases.tagId',
31
+ to: 'tags_releases.releaseId',
43
32
  },
44
33
  to: 'releases.id',
45
34
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nina-protocol/nina-db",
3
- "version": "0.0.65",
3
+ "version": "0.0.67",
4
4
  "description": "",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/index.js",
package/src/index.js CHANGED
@@ -31,6 +31,7 @@ export const Hub = Models.Hub
31
31
  export const Post = Models.Post
32
32
  export const Release = Models.Release
33
33
  export const Subscription = Models.Subscription
34
+ export const Tag = Models.Tag
34
35
  export const Transaction = Models.Transaction
35
36
  export const Verification = Models.Verification
36
37
  export const config = knexConfig
@@ -0,0 +1,30 @@
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
+ }),
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_releases');
30
+ };
@@ -261,8 +261,8 @@ export default class Release extends Model {
261
261
  join: {
262
262
  from: 'releases.id',
263
263
  through: {
264
- from: 'tags_content.releaseId',
265
- to: 'tags_content.tagId',
264
+ from: 'tags_releases.releaseId',
265
+ to: 'tags_releases.tagId',
266
266
  },
267
267
  to: 'tags.id',
268
268
  },
package/src/models/Tag.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Model } from 'objection';
2
+ import Release from './Release.js';
2
3
 
3
4
  export default class Tag extends Model {
4
5
  static tableName = 'tags';
@@ -11,7 +12,7 @@ export default class Tag extends Model {
11
12
  },
12
13
  }
13
14
 
14
- async findOrCreate(value) {
15
+ static findOrCreate = async (value) => {
15
16
  let tag = await Tag.query().where('value', value).first();
16
17
  if (!tag) {
17
18
  tag = await Tag.query().insert({ value });
@@ -19,31 +20,19 @@ export default class Tag extends Model {
19
20
  return tag;
20
21
  }
21
22
 
22
- async format () {
23
+ format = () => {
23
24
  delete this.id
24
25
  }
25
26
 
26
27
  static relationMappings = () => ({
27
- posts: {
28
- relation: Model.ManyToManyRelation,
29
- modelClass: 'Post',
30
- join: {
31
- from: 'tags.id',
32
- through: {
33
- from: 'tags_content.tagId',
34
- to: 'tags_content.postId',
35
- },
36
- to: 'posts.id',
37
- },
38
- },
39
28
  releases: {
40
29
  relation: Model.ManyToManyRelation,
41
- modelClass: 'Release',
30
+ modelClass: Release,
42
31
  join: {
43
32
  from: 'tags.id',
44
33
  through: {
45
- from: 'tags_content.tagId',
46
- to: 'tags_content.releaseId',
34
+ from: 'tags_releases.tagId',
35
+ to: 'tags_releases.releaseId',
47
36
  },
48
37
  to: 'releases.id',
49
38
  },