@itrocks/mysql-maintainer 0.0.10 → 0.0.11

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.
@@ -36,12 +36,13 @@ class MysqlMaintainer {
36
36
  throw 'Collection objects are not stored';
37
37
  }
38
38
  const joinTable = (0, mysql_1.joinTableName)(table1, table2);
39
- const query = 'CREATE TABLE `' + joinTable + '` (\n'
40
- + '`' + table1 + '_id` bigint NOT NULL,\n'
41
- + '`' + table2 + '_id` bigint NOT NULL,\n'
42
- + 'PRIMARY KEY (`' + table1 + '_id`,`' + table2 + '_id`)'
43
- + ')';
44
- console.log(query);
39
+ const query = `CREATE TABLE \`${joinTable}\` (
40
+ ${table1}_id int unsigned NOT NULL,
41
+ ${table2}_id int unsigned NOT NULL,
42
+ PRIMARY KEY (${table1}_id, ${table2}_id),
43
+ CONSTRAINT \`${joinTable}.${table1}_id\` FOREIGN KEY (${table1}_id) REFERENCES \`${table1}\` (id) ON DELETE CASCADE ON UPDATE CASCADE,
44
+ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \`${table2}\` (id) ON DELETE CASCADE ON UPDATE CASCADE
45
+ )`;
45
46
  await this.connection.query(query);
46
47
  return true;
47
48
  }
@@ -19,12 +19,13 @@ export class MysqlMaintainer {
19
19
  throw 'Collection objects are not stored';
20
20
  }
21
21
  const joinTable = joinTableName(table1, table2);
22
- const query = 'CREATE TABLE `' + joinTable + '` (\n'
23
- + '`' + table1 + '_id` bigint NOT NULL,\n'
24
- + '`' + table2 + '_id` bigint NOT NULL,\n'
25
- + 'PRIMARY KEY (`' + table1 + '_id`,`' + table2 + '_id`)'
26
- + ')';
27
- console.log(query);
22
+ const query = `CREATE TABLE \`${joinTable}\` (
23
+ ${table1}_id int unsigned NOT NULL,
24
+ ${table2}_id int unsigned NOT NULL,
25
+ PRIMARY KEY (${table1}_id, ${table2}_id),
26
+ CONSTRAINT \`${joinTable}.${table1}_id\` FOREIGN KEY (${table1}_id) REFERENCES \`${table1}\` (id) ON DELETE CASCADE ON UPDATE CASCADE,
27
+ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \`${table2}\` (id) ON DELETE CASCADE ON UPDATE CASCADE
28
+ )`;
28
29
  await this.connection.query(query);
29
30
  return true;
30
31
  }
package/package.json CHANGED
@@ -54,5 +54,5 @@
54
54
  "build:esm": "tsc -p tsconfig.esm.json"
55
55
  },
56
56
  "types": "./esm/mysql-maintainer.d.ts",
57
- "version": "0.0.10"
57
+ "version": "0.0.11"
58
58
  }