Skip to content

Commit 322b739

Browse files
authored
feat: added Epn, FLp, Log, Run, Tag and User models
2 parents 1c47f1e + 59e3567 commit 322b739

24 files changed

+742
-29
lines changed

docker-compose.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
# Mount the local working directory in the container for Nodemon
1010
- ".:/usr/src/app"
1111
- "/usr/src/app/node_modules"
12+
- "./scripts:/opt"
1213
ports:
1314
- "4000:4000"
1415
environment:

docs/CONFIGURATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
| DATABASE_USERNAME | The username which is used to authenticate against the database. | cern |
99
| DATABASE_PASSWORD | The password which is used to authenticate against the database. | cern |
1010
| DATABASE_NAME | The name of the database | bookkeeping |
11+
| DATABASE_TIMEZONE | The timezone of the database | Etc/GMT+0 |

lib/config/database.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let port = 3306;
1717
let username = 'cern';
1818
let password = 'cern';
1919
let database = 'bookkeeping';
20+
let timezone = 'Etc/GMT+2';
2021

2122
if (process.env.DATABASE_HOST) {
2223
host = process.env.DATABASE_HOST;
@@ -38,6 +39,10 @@ if (process.env.DATABASE_NAME) {
3839
database = process.env.DATABASE_NAME;
3940
}
4041

42+
if (process.env.DATABASE_TIMEZONE) {
43+
timezone = process.env.DATABASE_TIMEZONE;
44+
}
45+
4146
if (process.env.NODE_ENV === 'test') {
4247
database = `${database}_test`;
4348
}
@@ -49,4 +54,5 @@ module.exports = {
4954
username,
5055
password,
5156
database,
57+
timezone,
5258
};

lib/database/adapters/LogAdapter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LogAdapter extends IAdapter {
4040
}
4141

4242
/**
43-
* Converts the given entity object to an database object.
43+
* Converts the given entity object to a database object.
4444
*
4545
* @param {Object} entityObject Object to convert.
4646
* @returns {Object} Converted database object.
@@ -49,6 +49,10 @@ class LogAdapter extends IAdapter {
4949
return {
5050
id: entityObject.entryID,
5151
title: entityObject.title,
52+
subtype: 'run',
53+
origin: 'process',
54+
userId: 1,
55+
text: 'Yet another log',
5256
};
5357
}
5458
}

lib/database/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class SequelizeDatabase extends IDatabase {
4141
dialectOptions: {
4242
charset: 'utf8mb4',
4343
collate: 'utf8mb4_unicode_ci',
44+
timezone: Config.timezone,
4445
},
4546
logging: this.logger.debug.bind(this.logger),
47+
define: {
48+
underscored: true,
49+
},
4650
});
4751
}
4852

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
module.exports = {
15+
up: (queryInterface, Sequelize) => queryInterface.createTable('logs', {
16+
id: {
17+
allowNull: false,
18+
primaryKey: true,
19+
autoIncrement: true,
20+
type: Sequelize.INTEGER,
21+
},
22+
title: {
23+
allowNull: false,
24+
type: Sequelize.STRING,
25+
},
26+
text: {
27+
allowNull: false,
28+
type: Sequelize.TEXT,
29+
},
30+
subtype: {
31+
allowNull: false,
32+
type: Sequelize.ENUM('run', 'subsystem', 'announcement', 'intervention', 'comment'),
33+
},
34+
origin: {
35+
allowNull: false,
36+
type: Sequelize.ENUM('human', 'process'),
37+
},
38+
announcement_valid_until: {
39+
type: Sequelize.DATE,
40+
},
41+
created_at: {
42+
allowNull: false,
43+
type: Sequelize.DATE,
44+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
45+
},
46+
updated_at: {
47+
allowNull: false,
48+
type: Sequelize.DATE,
49+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
50+
},
51+
}, {
52+
timestamps: true,
53+
}),
54+
55+
down: (queryInterface, _Sequelize) => queryInterface.dropTable('logs'),
56+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
module.exports = {
15+
up: (queryInterface, Sequelize) => queryInterface.createTable('users', {
16+
id: {
17+
allowNull: false,
18+
autoIncrement: true,
19+
primaryKey: true,
20+
type: Sequelize.INTEGER,
21+
},
22+
external_id: {
23+
allowNull: false,
24+
type: Sequelize.INTEGER,
25+
},
26+
token: {
27+
type: Sequelize.STRING,
28+
},
29+
token_valid_until: {
30+
type: Sequelize.DATE,
31+
},
32+
created_at: {
33+
allowNull: false,
34+
type: Sequelize.DATE,
35+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
36+
},
37+
updated_at: {
38+
allowNull: false,
39+
type: Sequelize.DATE,
40+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
41+
},
42+
}),
43+
down: (queryInterface, _Sequelize) => queryInterface.dropTable('users'),
44+
};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
module.exports = {
15+
up: (queryInterface, Sequelize) => queryInterface.createTable('runs', {
16+
id: {
17+
allowNull: false,
18+
autoIncrement: true,
19+
primaryKey: true,
20+
type: Sequelize.INTEGER,
21+
},
22+
time_o2_start: {
23+
type: Sequelize.DATE,
24+
},
25+
time_o2_end: {
26+
type: Sequelize.DATE,
27+
},
28+
time_trg_start: {
29+
type: Sequelize.DATE,
30+
},
31+
time_trg_end: {
32+
type: Sequelize.DATE,
33+
},
34+
activity_id: {
35+
type: Sequelize.CHAR,
36+
},
37+
run_type: {
38+
type: Sequelize.ENUM('physics', 'cosmics', 'technical'),
39+
},
40+
run_quality: {
41+
type: Sequelize.ENUM('good', 'bad', 'unknown'),
42+
},
43+
n_detectors: {
44+
type: Sequelize.INTEGER,
45+
},
46+
n_flps: {
47+
type: Sequelize.INTEGER,
48+
},
49+
n_epns: {
50+
type: Sequelize.INTEGER,
51+
},
52+
n_subtimeframes: {
53+
type: Sequelize.INTEGER,
54+
},
55+
bytes_read_out: {
56+
type: Sequelize.INTEGER,
57+
},
58+
bytes_timeframe_builder: {
59+
type: Sequelize.INTEGER,
60+
},
61+
created_at: {
62+
allowNull: false,
63+
type: Sequelize.DATE,
64+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
65+
},
66+
updated_at: {
67+
allowNull: false,
68+
type: Sequelize.DATE,
69+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
70+
},
71+
}),
72+
73+
down: (queryInterface, _Sequelize) => queryInterface.dropTable('runs'),
74+
};

lib/database/migrations/20200426143121-migration-skeleton.js renamed to lib/database/migrations/20200506003500-create-tag.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212
*/
1313

1414
module.exports = {
15-
up: (queryInterface, Sequelize) => queryInterface.createTable('Logs', {
15+
up: (queryInterface, Sequelize) => queryInterface.createTable('tags', {
1616
id: {
1717
allowNull: false,
1818
autoIncrement: true,
1919
primaryKey: true,
2020
type: Sequelize.INTEGER,
2121
},
22-
title: {
22+
text: {
2323
allowNull: false,
2424
type: Sequelize.STRING,
2525
},
26-
createdAt: {
26+
created_at: {
2727
allowNull: false,
2828
type: Sequelize.DATE,
29+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
2930
},
30-
updatedAt: {
31+
updated_at: {
3132
allowNull: false,
3233
type: Sequelize.DATE,
34+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
3335
},
34-
}, {
35-
timestamps: true,
3636
}),
3737

38-
down: (queryInterface, _Sequelize) => queryInterface.dropTable('Logs'),
38+
down: (queryInterface, _Sequelize) => queryInterface.dropTable('tags'),
3939
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
module.exports = {
15+
up: (queryInterface, Sequelize) => queryInterface.createTable('flp_roles', {
16+
id: {
17+
allowNull: false,
18+
autoIncrement: true,
19+
primaryKey: true,
20+
type: Sequelize.INTEGER,
21+
},
22+
name: {
23+
type: Sequelize.STRING,
24+
},
25+
hostname: {
26+
type: Sequelize.STRING,
27+
},
28+
n_timeframes: {
29+
type: Sequelize.INTEGER,
30+
},
31+
bytes_processed: {
32+
type: Sequelize.INTEGER,
33+
},
34+
created_at: {
35+
allowNull: false,
36+
type: Sequelize.DATE,
37+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
38+
},
39+
updated_at: {
40+
allowNull: false,
41+
type: Sequelize.DATE,
42+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
43+
},
44+
}),
45+
46+
down: (queryInterface, _Sequelize) => queryInterface.dropTable('flp_roles'),
47+
};

0 commit comments

Comments
 (0)