1 | /**!
|
2 | * cnpmjs.org - models/tag.js
|
3 | *
|
4 | * Copyright(c) fengmk2 and other contributors.
|
5 | * MIT Licensed
|
6 | *
|
7 | * Authors:
|
8 | * fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
9 | */
|
10 |
|
11 | ;
|
12 |
|
13 | /**
|
14 | * Module dependencies.
|
15 | */
|
16 |
|
17 | /*
|
18 | CREATE TABLE IF NOT EXISTS `tag` (
|
19 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
20 | `gmt_create` datetime NOT NULL COMMENT 'create time',
|
21 | `gmt_modified` datetime NOT NULL COMMENT 'modified time',
|
22 | `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
|
23 | `tag` varchar(30) NOT NULL COMMENT 'tag name',
|
24 | `version` varchar(30) NOT NULL COMMENT 'module version',
|
25 | `module_id` bigint(20) unsigned NOT NULL COMMENT 'module id',
|
26 | PRIMARY KEY (`id`),
|
27 | UNIQUE KEY `tag_name_tag` (`name`, `tag`),
|
28 | KEY `tag_gmt_modified` (`gmt_modified`)
|
29 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module tag';
|
30 | */
|
31 |
|
32 | module.exports = function (sequelize, DataTypes) {
|
33 | return sequelize.define('Tag', {
|
34 | name: {
|
35 | type: DataTypes.STRING(100),
|
36 | allowNull: false,
|
37 | comment: 'module name',
|
38 | },
|
39 | tag: {
|
40 | type: DataTypes.STRING(30),
|
41 | allowNull: false,
|
42 | comment: 'tag name',
|
43 | },
|
44 | version: {
|
45 | type: DataTypes.STRING(30),
|
46 | allowNull: false,
|
47 | comment: 'module version',
|
48 | },
|
49 | module_id: {
|
50 | type: DataTypes.BIGINT(20),
|
51 | allowNull: false,
|
52 | comment: 'module id'
|
53 | }
|
54 | }, {
|
55 | tableName: 'tag',
|
56 | comment: 'module tag',
|
57 | indexes: [
|
58 | {
|
59 | unique: true,
|
60 | fields: ['name', 'tag']
|
61 | },
|
62 | {
|
63 | fields: ['gmt_modified']
|
64 | }
|
65 | ],
|
66 | classMethods: {
|
67 | findByNameAndTag: function* (name, tag) {
|
68 | return yield this.find({ where: { name: name, tag: tag } });
|
69 | }
|
70 | }
|
71 | });
|
72 | };
|