Skip to content

Commit ca45054

Browse files
authored
Merge pull request #30 from Human-Connection/29-sync-db-scheme-development-and-production
Sync db scheme development and production
2 parents 967f9fc + 5b4b3e8 commit ca45054

7 files changed

Lines changed: 191 additions & 135 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ build/Release
3535
# Dependency directories
3636
node_modules/
3737
jspm_packages/
38-
uploads/
38+
uploads/*
39+
!uploads/.gitignore
3940

4041
# TypeScript v1 declaration files
4142
typings/

core/db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ exports.verifyEntry = function(hash, callback){
9090
if(err) { console.log(err); callback(true); return; }
9191

9292
let sql = "UPDATE entries set email_confirmed = 1, confirmed_at = ? "
93-
+ "WHERE confirm_key = '?' AND confirmed_at is null;";
93+
+ "WHERE confirm_key = ? AND confirmed_at is null;";
9494

9595
// make the query
9696
connection.query(sql, [moment().valueOf(), hash], function(err, results) {

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
MYSQL_PASSWORD: 123456
1414
ports:
1515
- 3306:3306
16+
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
1617

1718
mailhog:
1819
container_name: mailhog

migrations/20190206134449-entries.js

Lines changed: 126 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -5,113 +5,136 @@ var type;
55
var seed;
66

77
/**
8-
* We receive the dbmigrate dependency from dbmigrate initially.
9-
* This enables us to not have to rely on NODE_PATH.
10-
*/
11-
exports.setup = function(options, seedLink) {
12-
dbm = options.dbmigrate;
13-
type = dbm.dataType;
14-
seed = seedLink;
8+
* We receive the dbmigrate dependency from dbmigrate initially.
9+
* This enables us to not have to rely on NODE_PATH.
10+
*/
11+
exports.setup = function (options, seedLink) {
12+
dbm = options.dbmigrate;
13+
type = dbm.dataType;
14+
seed = seedLink;
1515
};
1616

17-
exports.up = function(db, callback) {
18-
db.createTable('entries', {
19-
id: {
20-
type: 'int',
21-
unsigned: true,
22-
notNull: true,
23-
primaryKey: true,
24-
autoIncrement: true,
25-
length: 11
26-
},
27-
firstname: {
28-
type: 'string',
29-
length: 255,
30-
notNull: true,
31-
},
32-
lastname: {
33-
type: 'string',
34-
length: 255,
35-
defaultValue : null,
36-
},
37-
email: {
38-
type: 'string',
39-
length: 320,
40-
notNull: true,
41-
},
42-
country: {
43-
type: 'char',
44-
length: 2,
45-
defaultValue : null,
46-
},
47-
message: {
48-
type: 'text',
49-
notNull : true,
50-
},
51-
anon: {
52-
type: 'int',
53-
length: 1,
54-
defaultValue : 0,
55-
},
56-
ipv4: {
57-
type: 'string',
58-
length: 40,
59-
defaultValue : null,
60-
},
61-
image: {
62-
type: 'string',
63-
length: 255,
64-
defaultValue : null,
65-
},
66-
created_at: {
67-
type: 'string',
68-
length: 15,
69-
defaultValue : null,
70-
},
71-
updated_at: {
72-
type: 'string',
73-
length: 15,
74-
defaultValue : null,
75-
},
76-
confirm_key: {
77-
type: 'string',
78-
length: 75,
79-
defaultValue : null,
80-
},
81-
beta: {
82-
type: 'int',
83-
length: 1,
84-
defaultValue : 0,
85-
},
86-
newsletter: {
87-
type: 'int',
88-
length: 1,
89-
defaultValue : 0,
90-
},
91-
pax: {
92-
type: 'int',
93-
length: 1,
94-
defaultValue : 0,
95-
},
96-
email_confirmed: {
97-
type: 'int',
98-
length: 1,
99-
defaultValue : 0,
100-
},
101-
status: {
102-
type: 'int',
103-
length: 1,
104-
defaultValue : 0,
105-
},
106-
}, function(err) {
107-
if (err) return callback(err);
108-
return callback();
109-
});
17+
exports.up = function (db, callback) {
18+
db.createTable('entries', {
19+
id: {
20+
type: 'bigint',
21+
unsigned: true,
22+
notNull: true,
23+
primaryKey: true,
24+
autoIncrement: true,
25+
unique: true,
26+
length: 20
27+
},
28+
email: {
29+
type: 'string',
30+
length: 255,
31+
notNull: true,
32+
},
33+
firstname: {
34+
type: 'string',
35+
length: 255,
36+
notNull: true,
37+
},
38+
lastname: {
39+
type: 'string',
40+
length: 255,
41+
defaultValue: null,
42+
},
43+
message: {
44+
type: 'text',
45+
notNull: true,
46+
},
47+
country: {
48+
type: 'string',
49+
length: 4,
50+
defaultValue: null,
51+
},
52+
image: {
53+
type: 'string',
54+
length: 255,
55+
notNull: true,
56+
},
57+
ipv4: {
58+
type: 'string',
59+
length: 30,
60+
defaultValue: null,
61+
},
62+
ipv6: {
63+
type: 'string',
64+
length: 60,
65+
defaultValue: null,
66+
},
67+
email_confirmed: {
68+
type: 'smallint',
69+
length: 1,
70+
unsigned: true,
71+
notNull: true,
72+
defaultValue: '0',
73+
},
74+
confirm_key: {
75+
type: 'string',
76+
length: 255,
77+
defaultValue: null,
78+
},
79+
status: {
80+
type: 'smallint',
81+
length: 1,
82+
unsigned: true,
83+
notNull: true,
84+
defaultValue: '0',
85+
},
86+
anon: {
87+
type: 'smallint',
88+
length: 1,
89+
unsigned: true,
90+
notNull: true,
91+
defaultValue: '0',
92+
},
93+
created_at: {
94+
type: 'bigint',
95+
length: 20,
96+
unsigned: true,
97+
defaultValue: null,
98+
},
99+
updated_at: {
100+
type: 'bigint',
101+
length: 20,
102+
unsigned: true,
103+
defaultValue: null,
104+
},
105+
confirmed_at: {
106+
type: 'bigint',
107+
length: 20,
108+
unsigned: true,
109+
defaultValue: null,
110+
},
111+
beta: {
112+
type: 'smallint',
113+
length: 1,
114+
notNull: true,
115+
defaultValue: '0',
116+
},
117+
newsletter: {
118+
type: 'smallint',
119+
length: 1,
120+
notNull: true,
121+
defaultValue: '0',
122+
},
123+
pax: {
124+
type: 'smallint',
125+
length: 1,
126+
notNull: true,
127+
defaultValue: '0',
128+
},
129+
}, function (err) {
130+
if (err) return callback(err);
131+
return callback();
132+
});
110133
};
111-
exports.down = function(db, callback) {
112-
db.dropTable('entries', callback);
134+
exports.down = function (db, callback) {
135+
db.dropTable('entries', callback);
113136
};
114137

115138
exports._meta = {
116-
"version": 1
139+
'version': 1
117140
};

migrations/20190206140226-apikeys.js

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,64 @@ var type;
55
var seed;
66

77
/**
8-
* We receive the dbmigrate dependency from dbmigrate initially.
9-
* This enables us to not have to rely on NODE_PATH.
10-
*/
11-
exports.setup = function(options, seedLink) {
12-
dbm = options.dbmigrate;
13-
type = dbm.dataType;
14-
seed = seedLink;
8+
* We receive the dbmigrate dependency from dbmigrate initially.
9+
* This enables us to not have to rely on NODE_PATH.
10+
*/
11+
exports.setup = function (options, seedLink) {
12+
dbm = options.dbmigrate;
13+
type = dbm.dataType;
14+
seed = seedLink;
1515
};
1616

17-
exports.up = function(db, callback) {
18-
db.createTable('apikeys', {
19-
secret: {
20-
type: 'string',
21-
length: 100,
22-
unique: true,
23-
notNull: true,
24-
},
25-
valid: {
26-
type: 'int',
27-
length: 1,
28-
default: 0
29-
},
30-
}, function(err) {
31-
if (err) return callback(err);
32-
return callback();
33-
});
17+
exports.up = function (db, callback) {
18+
db.createTable('apikeys', {
19+
id: {
20+
type: 'bigint',
21+
unsigned: true,
22+
notNull: true,
23+
primaryKey: true,
24+
autoIncrement: true,
25+
length: 64
26+
},
27+
secret: {
28+
type: 'string',
29+
length: 64,
30+
unique: true,
31+
notNull: true,
32+
},
33+
valid: {
34+
type: 'smallint',
35+
length: 1,
36+
unsigned: true,
37+
notNull: true,
38+
defaultValue: '0'
39+
},
40+
expire_at: {
41+
type: 'bigint',
42+
length: 64,
43+
notNull: true,
44+
},
45+
created_at: {
46+
type: 'bigint',
47+
length: 64,
48+
unsigned: true,
49+
notNull: true,
50+
},
51+
updated_at: {
52+
type: 'bigint',
53+
length: 64,
54+
unsigned: true,
55+
notNull: true,
56+
},
57+
}, function (err) {
58+
if (err) return callback(err);
59+
return callback();
60+
});
3461
};
35-
exports.down = function(db, callback) {
36-
db.dropTable('apikeys', callback);
62+
exports.down = function (db, callback) {
63+
db.dropTable('apikeys', callback);
3764
};
3865

3966
exports._meta = {
40-
"version": 1
67+
'version': 1
4168
};

seed.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DATABASE << EOF
3-
INSERT INTO \`clock_of_change\`.\`apikeys\` (\`secret\`, \`valid\`) VALUES ('secret', '1');
4-
INSERT INTO \`clock_of_change\`.\`entries\` (\`firstname\`, \`lastname\`, \`email\`, \`country\`, \`message\`, \`confirm_key\`, \`beta\`, \`newsletter\`, \`pax\`, \`email_confirmed\`, \`status\`) VALUES ('Pamela', 'Musterfrau', 'pamela@example.org', 'US', 'Let us change the world!', 'confirm', '1', '0', '1', '1', '1');
5-
INSERT INTO \`clock_of_change\`.\`entries\` (\`firstname\`, \`lastname\`, \`email\`, \`country\`, \`message\`, \`confirm_key\`, \`beta\`, \`newsletter\`, \`pax\`, \`email_confirmed\`, \`status\`) VALUES ('Max', 'Mustermann', 'max@example.org', 'DE', 'Lasst uns die Welt verbessern!', 'confirm', '0', '1', '1', '1', '1');
3+
INSERT INTO \`clock_of_change\`.\`apikeys\` (\`secret\`, \`valid\`, \`expire_at\`, \`created_at\`, \`updated_at\`) VALUES ('secret', '1', 1893456001, 1552060594, 1552060594);
4+
INSERT INTO \`clock_of_change\`.\`entries\` (\`email\`, \`firstname\`, \`lastname\`, \`message\`, \`country\`, \`image\`, \`email_confirmed\`, \`confirm_key\`, \`status\`, \`created_at\`, \`updated_at\`, \`confirmed_at\`, \`newsletter\`, \`pax\`) VALUES ('pamela@example.org', 'Pamela', 'Musterfrau', 'Let us change the world!', 'US', '', '1', 'confirm', '1', '1552060594', '1552060594', '1552060594', '1', '1');
5+
INSERT INTO \`clock_of_change\`.\`entries\` (\`email\`, \`firstname\`, \`lastname\`, \`message\`, \`country\`, \`image\`, \`email_confirmed\`, \`confirm_key\`, \`status\`, \`created_at\`, \`updated_at\`, \`confirmed_at\`, \`newsletter\`, \`pax\`) VALUES ('max@example.org', 'Max', 'Mustermann', 'Lasst uns die Welt verbessern!', 'DE', '', '1', 'confirm', '1', '1552060594', '1552060594', '1552060594', '0', '1');
66
EOF

uploads/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

0 commit comments

Comments
 (0)