Просмотр исходного кода

:tada: first commit | more generic version

master
j 5 лет назад
Сommit
857ae2a905

+ 19
- 0
.env.sample Просмотреть файл

@@ -0,0 +1,19 @@
1
+SEED_U=root
2
+SEED_PW=root
3
+SEED_HOST=127.0.0.1
4
+SEED_PORT=3306
5
+SEED_DIALECT=mariadb
6
+SEED_DB=unclean
7
+
8
+TARGET_U=root
9
+TARGET_PW=thisisapassword
10
+TARGET_HOST=127.0.0.1
11
+TARGET_PORT=3380
12
+TARGET_DIALECT=mariadb
13
+TARGET_DB=current_db
14
+
15
+LOCAL_SQLITE=cleaned
16
+
17
+POST_TYPES={"post": "post", "page": "page", "attachment": "attachment"}
18
+
19
+METAKEYS=[]

+ 20
- 0
.gitignore Просмотреть файл

@@ -0,0 +1,20 @@
1
+<<<<<<< HEAD
2
+.DS_STORE
3
+.vscode
4
+
5
+.env
6
+node_modules
7
+.dump.sql
8
+
9
+cleaned/*
10
+=======
11
+.DS_STORE
12
+.vscode
13
+
14
+.env
15
+node_modules
16
+
17
+cleaned/*
18
+
19
+dump.sql
20
+>>>>>>> 18dc75b (:sparkles: moving customizations to env file)

+ 39
- 0
README.md Просмотреть файл

@@ -0,0 +1,39 @@
1
+# moving.co CLI
2
+
3
+A CLI to move sql databases around.
4
+
5
+## :white_check_mark: Prerequisites
6
+
7
+You will need...
8
+
9
+### Node.js 14+
10
+
11
+* OSX: `brew install node` using [Homebrew](http://brew.sh/)
12
+* Linux: `apt install nodejs` ([see Ubuntu/Debian specific instructions](https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions)) or `pacman -S nodejs` (Arch Linux)
13
+* Windows: [Install](https://nodejs.org/en/download/)
14
+
15
+## :package: Installation
16
+
17
+1. Please enter your dB details in the `.env.sample` file, and rename to `.env`
18
+2. Add entries for the `POST_TYPES` you're interested in
19
+2. Add any custom `METAKEYS` associated with your posts
20
+3. Start up the seed container using `docker-compose up -d`
21
+4. Load your dirty database `docker exec -i scratch-mariadb mysql -uroot -proot --database=unclean < ./dump.sql`
22
+
23
+## :electric_plug: Run
24
+
25
+1. Run `npm get` to grab data-models from your existing database
26
+2. Run `npm run migrate` to create tables from data-models in a temproary sqlite database
27
+
28
+## :robot: Deployment
29
+
30
+TBD
31
+
32
+## :pill: Tests & Code Quality
33
+
34
+TBD
35
+
36
+## :heart: Built With
37
+
38
+* [Sequelize](https://sequelize.org/) - an ORM tool
39
+* [Umzug](https://github.com/sequelize/umzug) - Migration tracking

+ 16
- 0
docker-compose.yml Просмотреть файл

@@ -0,0 +1,16 @@
1
+    version: '3'
2
+
3
+    services:
4
+      working-db:
5
+        image: mariadb:latest
6
+        container_name: scratch-mariadb
7
+        volumes:
8
+          - container-volume:/var/lib/mysql
9
+        environment:
10
+          MYSQL_ROOT_PASSWORD: root
11
+          MYSQL_DATABASE: unclean
12
+        ports:
13
+          - '3306:3306'
14
+
15
+    volumes:
16
+      container-volume:

+ 1
- 0
dump.sample.sql Просмотреть файл

@@ -0,0 +1 @@
1
+-- REPLACE ME with your actual SQL dump

+ 77
- 0
helpers.js Просмотреть файл

@@ -0,0 +1,77 @@
1
+const { default: initModels } = require('./models/init-models')
2
+
3
+module.exports = {
4
+    /**
5
+     * Grabs the actual row information as JSON
6
+     * and packs it up into an array
7
+     *
8
+     * @param {array} postList
9
+     * @param {string} typeToFind
10
+     * @returns array
11
+     */
12
+    getPostData: (postList, typeToFind) => {
13
+        return postList.reduce((data, post) => {
14
+            /**
15
+             * Double-check our post matches the type
16
+             */
17
+            if(typeToFind && post.dataValues.post_type != typeToFind) {
18
+                return data
19
+            }
20
+
21
+            /**
22
+             * ONLY add matching postData to our data array
23
+             * and omit all the extra sequelize meta data
24
+             * by pushing the dataValues key
25
+             */
26
+            data.push(post.dataValues)
27
+            return data
28
+        }, [])
29
+    },
30
+
31
+    /**
32
+     * Helper to find post descendants
33
+     *
34
+     * @param {array} parentList
35
+     * @param {object} db - sequelize instance
36
+     * @param {function} getParams - lambda returning param object { rule: 'example' }
37
+     * @returns array
38
+     */
39
+    findDescendants: async (parentList, db, getParams) => {
40
+        const matchList = []
41
+        for(let post of parentList) {
42
+            const match = await db.findAll({ where: getParams(post) })
43
+            match.forEach(entity => matchList.push(entity))
44
+        }
45
+        return matchList
46
+    },
47
+
48
+    /**
49
+     * The keys we want from the postmeta table
50
+     */
51
+    metakeys: [
52
+        '_wp_attached_file',
53
+        '_wp_attachment_metadata',
54
+        '_thumbnail_id',
55
+        ...process.env.METAKEYS
56
+    ],
57
+
58
+    /**
59
+     * The post type names we're interested in
60
+     *
61
+     * 1. Status types we migrate
62
+     */
63
+    types: {
64
+        ...process.env.POST_TYPES,
65
+        /* 1 */
66
+        status: ['publish']
67
+    },
68
+
69
+    /**
70
+     * dB creation helper
71
+     * !: Don't touch
72
+     *
73
+     * @param {object} models - sequelize instance
74
+     * @returns object - all models associated with instance
75
+     */
76
+    db: models => initModels(models),
77
+}

+ 67
- 0
index.js Просмотреть файл

@@ -0,0 +1,67 @@
1
+const dotenv = require('dotenv')
2
+dotenv.config()
3
+
4
+const Sequelize = require('sequelize')
5
+const path = require('path')
6
+const Umzug = require('umzug')
7
+
8
+const d = new Date();
9
+const datestring = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate()
10
+const timestring = d.getHours() + ":" + d.getMinutes();
11
+
12
+/**
13
+ * Creates a basic sqlite database at the path
14
+ * provided by your .env file
15
+ */
16
+// MIGRATE TO
17
+// const targetDbSequelizeInstance = new Sequelize({
18
+//     dialect: 'sqlite',
19
+//     storage: `./cleaned/${datestring}/${process.env.LOCAL_SQLITE + '_' + timestring + '.sqlite'}`
20
+// })
21
+const targetDbSequelizeInstance = new Sequelize(
22
+    process.env.TARGET_DB,
23
+    process.env.TARGET_U,
24
+    process.env.TARGET_PW,
25
+    {
26
+        host: process.env.TARGET_HOST,
27
+        port: process.env.TARGET_PORT,
28
+        dialect: process.env.TARGET_DIALECT,
29
+        logging: false
30
+    }
31
+)
32
+
33
+// SEED FROM
34
+const seedDb = new Sequelize(
35
+    process.env.SEED_DB,
36
+    process.env.SEED_U,
37
+    process.env.SEED_PW,
38
+    {
39
+        host: process.env.SEED_HOST,
40
+        dialect: process.env.SEED_DIALECT,
41
+        logging: false
42
+    }
43
+)
44
+
45
+const migrator = new Umzug({
46
+    migrations: {
47
+        path: path.join(__dirname, './migrations'),
48
+        params: [
49
+            targetDbSequelizeInstance.getQueryInterface()
50
+        ]
51
+    },
52
+    storage: 'sequelize',
53
+    storageOptions: { sequelize: targetDbSequelizeInstance }
54
+})
55
+
56
+;(async () => {
57
+    /**
58
+     * Checks migrations and run them if they are not already applied
59
+     */
60
+    await migrator.up()
61
+
62
+    // Uncomment to destroy things
63
+    // await migrator.down()
64
+    console.log('\n***\n\nAll migrations performed successfully!\n' )
65
+})()
66
+
67
+module.exports = seedDb

+ 24
- 0
migrations/00_create_tables.js Просмотреть файл

@@ -0,0 +1,24 @@
1
+const initModels = require('../models/init-models')
2
+
3
+/**
4
+ * All migrations MUST provide a `up` and `down` async functions
5
+ */
6
+module.exports = {
7
+    up: async query => {
8
+        const models = initModels(query.sequelize)
9
+
10
+        /**
11
+         * Create a table for model as defined by model files
12
+         * in /models/ directory
13
+         */
14
+        for (let model of Object.values(models)) {
15
+            // Create for each /models/*.js file
16
+            // Example: models.User.sync()
17
+            await model.sync()
18
+        }
19
+    },
20
+
21
+    down: async query => {
22
+        // Do nothing...
23
+    },
24
+}

+ 78
- 0
migrations/01_insert_example.js Просмотреть файл

@@ -0,0 +1,78 @@
1
+const seedDb = require('../index')
2
+const h = require('../helpers')
3
+
4
+/**
5
+ * What TYPE are you migrating?
6
+ */ 
7
+const mainType = h.types.post
8
+
9
+module.exports = {
10
+    up: async query => {
11
+        const fromSeedDB = h.db(seedDb)
12
+        const toCleanDB = h.db(query.sequelize)
13
+
14
+        /**
15
+         * Our base list of posts matching mainType to migrate
16
+         */
17
+        const matchingPosts = await fromSeedDB.wp_posts.findAll({
18
+            where: {
19
+                post_type: mainType,
20
+                post_status: h.types.status
21
+            }
22
+        })
23
+        const postsToWrite = h.getPostData(matchingPosts, mainType)
24
+
25
+        /**
26
+         * Attachments matching ID's in postsToWrite
27
+         */
28
+        const matchingAttachments = await h.findDescendants(
29
+            postsToWrite,
30
+            fromSeedDB.wp_posts,
31
+            post => ({
32
+                post_type: h.types.attachment,
33
+                post_parent: post.ID
34
+            })
35
+        )
36
+        const attachmentsToWrite = h.getPostData(matchingAttachments, h.types.attachment)
37
+
38
+        /**
39
+         * Attachments are POSTS too, so we combine the two lists
40
+         * before we can find postmeta keys we care about
41
+         *
42
+         * 1. Meta keys are match anything in our h.metakeys list
43
+         *    using opt.in to evaluate h.metakeys.indexOf(post)
44
+         */
45
+        const postmeta = await h.findDescendants(
46
+            [...matchingPosts, ...matchingAttachments],
47
+            fromSeedDB.wp_postmeta,
48
+            post => ({
49
+                post_id: post.ID,
50
+                /* 1 */
51
+                meta_key: h.metakeys
52
+            })
53
+        )
54
+        const postmetaToWrite = h.getPostData(postmeta, false)
55
+        
56
+        /**
57
+         * INSERT in our new db with some options
58
+         * 1. First we insert our episode POST and attachments
59
+         *    to the posts table
60
+         * 2. Then we add our matching POSTMETA entries to
61
+         *    the postmeta table
62
+         */
63
+        const createOptions = { validate: true }
64
+        /* 1 */
65
+        await toCleanDB.wp_posts.bulkCreate([
66
+            ...postsToWrite,
67
+            ...attachmentsToWrite
68
+        ], createOptions)
69
+        /* 2 */
70
+        await toCleanDB.wp_postmeta.bulkCreate([
71
+            ...postmetaToWrite
72
+        ], createOptions)
73
+    },
74
+
75
+    down: async query => {
76
+        // Do nothing...
77
+    },
78
+}

+ 37
- 0
models/init-models.js Просмотреть файл

@@ -0,0 +1,37 @@
1
+var DataTypes = require("sequelize").DataTypes;
2
+var _wp_options = require("./wp_options");
3
+var _wp_postmeta = require("./wp_postmeta");
4
+var _wp_posts = require("./wp_posts");
5
+var _wp_term_relationships = require("./wp_term_relationships");
6
+var _wp_term_taxonomy = require("./wp_term_taxonomy");
7
+var _wp_termmeta = require("./wp_termmeta");
8
+var _wp_terms = require("./wp_terms");
9
+var _wp_usermeta = require("./wp_usermeta");
10
+var _wp_users = require("./wp_users");
11
+
12
+function initModels(sequelize) {
13
+  var wp_options = _wp_options(sequelize, DataTypes);
14
+  var wp_postmeta = _wp_postmeta(sequelize, DataTypes);
15
+  var wp_posts = _wp_posts(sequelize, DataTypes);
16
+  var wp_term_relationships = _wp_term_relationships(sequelize, DataTypes);
17
+  var wp_term_taxonomy = _wp_term_taxonomy(sequelize, DataTypes);
18
+  var wp_termmeta = _wp_termmeta(sequelize, DataTypes);
19
+  var wp_terms = _wp_terms(sequelize, DataTypes);
20
+  var wp_usermeta = _wp_usermeta(sequelize, DataTypes);
21
+  var wp_users = _wp_users(sequelize, DataTypes);
22
+
23
+  return {
24
+    wp_options,
25
+    wp_postmeta,
26
+    wp_posts,
27
+    wp_term_relationships,
28
+    wp_term_taxonomy,
29
+    wp_termmeta,
30
+    wp_terms,
31
+    wp_usermeta,
32
+    wp_users,
33
+  };
34
+}
35
+module.exports = initModels;
36
+module.exports.initModels = initModels;
37
+module.exports.default = initModels;

+ 59
- 0
models/wp_commentmeta.js Просмотреть файл

@@ -0,0 +1,59 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = (sequelize, DataTypes) => {
3
+  return wp_commentmeta.init(sequelize, DataTypes);
4
+}
5
+
6
+class wp_commentmeta extends Sequelize.Model {
7
+  static init(sequelize, DataTypes) {
8
+  super.init({
9
+    meta_id: {
10
+      autoIncrement: true,
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      primaryKey: true
14
+    },
15
+    comment_id: {
16
+      type: DataTypes.BIGINT.UNSIGNED,
17
+      allowNull: false,
18
+      defaultValue: 0
19
+    },
20
+    meta_key: {
21
+      type: DataTypes.STRING(255),
22
+      allowNull: true
23
+    },
24
+    meta_value: {
25
+      type: DataTypes.TEXT,
26
+      allowNull: true
27
+    }
28
+  }, {
29
+    sequelize,
30
+    tableName: 'wp_commentmeta',
31
+    timestamps: false,
32
+    indexes: [
33
+      {
34
+        name: "PRIMARY",
35
+        unique: true,
36
+        using: "BTREE",
37
+        fields: [
38
+          { name: "meta_id" },
39
+        ]
40
+      },
41
+      {
42
+        name: "comment_id",
43
+        using: "BTREE",
44
+        fields: [
45
+          { name: "comment_id" },
46
+        ]
47
+      },
48
+      {
49
+        name: "meta_key",
50
+        using: "BTREE",
51
+        fields: [
52
+          { name: "meta_key", length: 191 },
53
+        ]
54
+      },
55
+    ]
56
+  });
57
+  return wp_commentmeta;
58
+  }
59
+}

+ 136
- 0
models/wp_comments.js Просмотреть файл

@@ -0,0 +1,136 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = (sequelize, DataTypes) => {
3
+  return wp_comments.init(sequelize, DataTypes);
4
+}
5
+
6
+class wp_comments extends Sequelize.Model {
7
+  static init(sequelize, DataTypes) {
8
+  super.init({
9
+    comment_ID: {
10
+      autoIncrement: true,
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      primaryKey: true
14
+    },
15
+    comment_post_ID: {
16
+      type: DataTypes.BIGINT.UNSIGNED,
17
+      allowNull: false,
18
+      defaultValue: 0
19
+    },
20
+    comment_author: {
21
+      type: DataTypes.TEXT,
22
+      allowNull: false
23
+    },
24
+    comment_author_email: {
25
+      type: DataTypes.STRING(100),
26
+      allowNull: false,
27
+      defaultValue: ""
28
+    },
29
+    comment_author_url: {
30
+      type: DataTypes.STRING(200),
31
+      allowNull: false,
32
+      defaultValue: ""
33
+    },
34
+    comment_author_IP: {
35
+      type: DataTypes.STRING(100),
36
+      allowNull: false,
37
+      defaultValue: ""
38
+    },
39
+    comment_date: {
40
+      type: DataTypes.DATE,
41
+      allowNull: false,
42
+      defaultValue: "0000-00-00 00:00:00"
43
+    },
44
+    comment_date_gmt: {
45
+      type: DataTypes.DATE,
46
+      allowNull: false,
47
+      defaultValue: "0000-00-00 00:00:00"
48
+    },
49
+    comment_content: {
50
+      type: DataTypes.TEXT,
51
+      allowNull: false
52
+    },
53
+    comment_karma: {
54
+      type: DataTypes.INTEGER,
55
+      allowNull: false,
56
+      defaultValue: 0
57
+    },
58
+    comment_approved: {
59
+      type: DataTypes.STRING(20),
60
+      allowNull: false,
61
+      defaultValue: "1"
62
+    },
63
+    comment_agent: {
64
+      type: DataTypes.STRING(255),
65
+      allowNull: false,
66
+      defaultValue: ""
67
+    },
68
+    comment_type: {
69
+      type: DataTypes.STRING(20),
70
+      allowNull: false,
71
+      defaultValue: "comment"
72
+    },
73
+    comment_parent: {
74
+      type: DataTypes.BIGINT.UNSIGNED,
75
+      allowNull: false,
76
+      defaultValue: 0
77
+    },
78
+    user_id: {
79
+      type: DataTypes.BIGINT.UNSIGNED,
80
+      allowNull: false,
81
+      defaultValue: 0
82
+    }
83
+  }, {
84
+    sequelize,
85
+    tableName: 'wp_comments',
86
+    timestamps: false,
87
+    indexes: [
88
+      {
89
+        name: "PRIMARY",
90
+        unique: true,
91
+        using: "BTREE",
92
+        fields: [
93
+          { name: "comment_ID" },
94
+        ]
95
+      },
96
+      {
97
+        name: "comment_post_ID",
98
+        using: "BTREE",
99
+        fields: [
100
+          { name: "comment_post_ID" },
101
+        ]
102
+      },
103
+      {
104
+        name: "comment_approved_date_gmt",
105
+        using: "BTREE",
106
+        fields: [
107
+          { name: "comment_approved" },
108
+          { name: "comment_date_gmt" },
109
+        ]
110
+      },
111
+      {
112
+        name: "comment_date_gmt",
113
+        using: "BTREE",
114
+        fields: [
115
+          { name: "comment_date_gmt" },
116
+        ]
117
+      },
118
+      {
119
+        name: "comment_parent",
120
+        using: "BTREE",
121
+        fields: [
122
+          { name: "comment_parent" },
123
+        ]
124
+      },
125
+      {
126
+        name: "comment_author_email",
127
+        using: "BTREE",
128
+        fields: [
129
+          { name: "comment_author_email", length: 10 },
130
+        ]
131
+      },
132
+    ]
133
+  });
134
+  return wp_comments;
135
+  }
136
+}

+ 98
- 0
models/wp_links.js Просмотреть файл

@@ -0,0 +1,98 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = (sequelize, DataTypes) => {
3
+  return wp_links.init(sequelize, DataTypes);
4
+}
5
+
6
+class wp_links extends Sequelize.Model {
7
+  static init(sequelize, DataTypes) {
8
+  super.init({
9
+    link_id: {
10
+      autoIncrement: true,
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      primaryKey: true
14
+    },
15
+    link_url: {
16
+      type: DataTypes.STRING(255),
17
+      allowNull: false,
18
+      defaultValue: ""
19
+    },
20
+    link_name: {
21
+      type: DataTypes.STRING(255),
22
+      allowNull: false,
23
+      defaultValue: ""
24
+    },
25
+    link_image: {
26
+      type: DataTypes.STRING(255),
27
+      allowNull: false,
28
+      defaultValue: ""
29
+    },
30
+    link_target: {
31
+      type: DataTypes.STRING(25),
32
+      allowNull: false,
33
+      defaultValue: ""
34
+    },
35
+    link_description: {
36
+      type: DataTypes.STRING(255),
37
+      allowNull: false,
38
+      defaultValue: ""
39
+    },
40
+    link_visible: {
41
+      type: DataTypes.STRING(20),
42
+      allowNull: false,
43
+      defaultValue: "Y"
44
+    },
45
+    link_owner: {
46
+      type: DataTypes.BIGINT.UNSIGNED,
47
+      allowNull: false,
48
+      defaultValue: 1
49
+    },
50
+    link_rating: {
51
+      type: DataTypes.INTEGER,
52
+      allowNull: false,
53
+      defaultValue: 0
54
+    },
55
+    link_updated: {
56
+      type: DataTypes.DATE,
57
+      allowNull: false,
58
+      defaultValue: "0000-00-00 00:00:00"
59
+    },
60
+    link_rel: {
61
+      type: DataTypes.STRING(255),
62
+      allowNull: false,
63
+      defaultValue: ""
64
+    },
65
+    link_notes: {
66
+      type: DataTypes.TEXT,
67
+      allowNull: false
68
+    },
69
+    link_rss: {
70
+      type: DataTypes.STRING(255),
71
+      allowNull: false,
72
+      defaultValue: ""
73
+    }
74
+  }, {
75
+    sequelize,
76
+    tableName: 'wp_links',
77
+    timestamps: false,
78
+    indexes: [
79
+      {
80
+        name: "PRIMARY",
81
+        unique: true,
82
+        using: "BTREE",
83
+        fields: [
84
+          { name: "link_id" },
85
+        ]
86
+      },
87
+      {
88
+        name: "link_visible",
89
+        using: "BTREE",
90
+        fields: [
91
+          { name: "link_visible" },
92
+        ]
93
+      },
94
+    ]
95
+  });
96
+  return wp_links;
97
+  }
98
+}

+ 54
- 0
models/wp_options.js Просмотреть файл

@@ -0,0 +1,54 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_options', {
4
+    option_id: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    option_name: {
11
+      type: DataTypes.STRING(191),
12
+      allowNull: true,
13
+      unique: "option_name"
14
+    },
15
+    option_value: {
16
+      type: DataTypes.TEXT,
17
+      allowNull: false
18
+    },
19
+    autoload: {
20
+      type: DataTypes.STRING(20),
21
+      allowNull: false,
22
+      defaultValue: "yes"
23
+    }
24
+  }, {
25
+    sequelize,
26
+    tableName: 'wp_options',
27
+    timestamps: false,
28
+    indexes: [
29
+      {
30
+        name: "PRIMARY",
31
+        unique: true,
32
+        using: "BTREE",
33
+        fields: [
34
+          { name: "option_id" },
35
+        ]
36
+      },
37
+      {
38
+        name: "option_name",
39
+        unique: true,
40
+        using: "BTREE",
41
+        fields: [
42
+          { name: "option_name" },
43
+        ]
44
+      },
45
+      {
46
+        name: "autoload",
47
+        using: "BTREE",
48
+        fields: [
49
+          { name: "autoload" },
50
+        ]
51
+      },
52
+    ]
53
+  });
54
+};

+ 27
- 0
models/wp_postmeta.js Просмотреть файл

@@ -0,0 +1,27 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_postmeta', {
4
+    meta_id: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    post_id: {
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      defaultValue: 0
14
+    },
15
+    meta_key: {
16
+      type: DataTypes.STRING(255),
17
+      allowNull: true
18
+    },
19
+    meta_value: {
20
+      type: DataTypes.TEXT,
21
+      allowNull: true
22
+    }
23
+  }, {
24
+    sequelize,
25
+    timestamps: false,
26
+  });
27
+};

+ 118
- 0
models/wp_posts.js Просмотреть файл

@@ -0,0 +1,118 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_posts', {
4
+    ID: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    post_author: {
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      defaultValue: 0
14
+    },
15
+    post_date: {
16
+      type: DataTypes.DATE,
17
+      allowNull: false,
18
+      defaultValue: "0000-00-00 00:00:00"
19
+    },
20
+    post_date_gmt: {
21
+      type: DataTypes.DATE,
22
+      allowNull: false,
23
+      defaultValue: "0000-00-00 00:00:00"
24
+    },
25
+    post_content: {
26
+      type: DataTypes.TEXT,
27
+      allowNull: false
28
+    },
29
+    post_title: {
30
+      type: DataTypes.TEXT,
31
+      allowNull: false
32
+    },
33
+    post_excerpt: {
34
+      type: DataTypes.TEXT,
35
+      allowNull: false
36
+    },
37
+    post_status: {
38
+      type: DataTypes.STRING(20),
39
+      allowNull: false,
40
+      defaultValue: "publish"
41
+    },
42
+    comment_status: {
43
+      type: DataTypes.STRING(20),
44
+      allowNull: false,
45
+      defaultValue: "open"
46
+    },
47
+    ping_status: {
48
+      type: DataTypes.STRING(20),
49
+      allowNull: false,
50
+      defaultValue: "open"
51
+    },
52
+    post_password: {
53
+      type: DataTypes.STRING(255),
54
+      allowNull: false,
55
+      defaultValue: ""
56
+    },
57
+    post_name: {
58
+      type: DataTypes.STRING(200),
59
+      allowNull: false,
60
+      defaultValue: ""
61
+    },
62
+    to_ping: {
63
+      type: DataTypes.TEXT,
64
+      allowNull: false
65
+    },
66
+    pinged: {
67
+      type: DataTypes.TEXT,
68
+      allowNull: false
69
+    },
70
+    post_modified: {
71
+      type: DataTypes.DATE,
72
+      allowNull: false,
73
+      defaultValue: "0000-00-00 00:00:00"
74
+    },
75
+    post_modified_gmt: {
76
+      type: DataTypes.DATE,
77
+      allowNull: false,
78
+      defaultValue: "0000-00-00 00:00:00"
79
+    },
80
+    post_content_filtered: {
81
+      type: DataTypes.TEXT,
82
+      allowNull: false
83
+    },
84
+    post_parent: {
85
+      type: DataTypes.BIGINT.UNSIGNED,
86
+      allowNull: false,
87
+      defaultValue: 0
88
+    },
89
+    guid: {
90
+      type: DataTypes.STRING(255),
91
+      allowNull: false,
92
+      defaultValue: ""
93
+    },
94
+    menu_order: {
95
+      type: DataTypes.INTEGER,
96
+      allowNull: false,
97
+      defaultValue: 0
98
+    },
99
+    post_type: {
100
+      type: DataTypes.STRING(20),
101
+      allowNull: false,
102
+      defaultValue: "post"
103
+    },
104
+    post_mime_type: {
105
+      type: DataTypes.STRING(100),
106
+      allowNull: false,
107
+      defaultValue: ""
108
+    },
109
+    comment_count: {
110
+      type: DataTypes.BIGINT,
111
+      allowNull: false,
112
+      defaultValue: 0
113
+    }
114
+  }, {
115
+    sequelize,
116
+    timestamps: false,
117
+  });
118
+};

+ 25
- 0
models/wp_term_relationships.js Просмотреть файл

@@ -0,0 +1,25 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_term_relationships', {
4
+    object_id: {
5
+      type: DataTypes.BIGINT.UNSIGNED,
6
+      allowNull: false,
7
+      defaultValue: 0,
8
+      primaryKey: true
9
+    },
10
+    term_taxonomy_id: {
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      defaultValue: 0,
14
+      primaryKey: true
15
+    },
16
+    term_order: {
17
+      type: DataTypes.INTEGER,
18
+      allowNull: false,
19
+      defaultValue: 0
20
+    }
21
+  }, {
22
+    sequelize,
23
+    timestamps: false,
24
+  });
25
+};

+ 38
- 0
models/wp_term_taxonomy.js Просмотреть файл

@@ -0,0 +1,38 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_term_taxonomy', {
4
+    term_taxonomy_id: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    term_id: {
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      defaultValue: 0
14
+    },
15
+    taxonomy: {
16
+      type: DataTypes.STRING(32),
17
+      allowNull: false,
18
+      defaultValue: ""
19
+    },
20
+    description: {
21
+      type: DataTypes.TEXT,
22
+      allowNull: false
23
+    },
24
+    parent: {
25
+      type: DataTypes.BIGINT.UNSIGNED,
26
+      allowNull: false,
27
+      defaultValue: 0
28
+    },
29
+    count: {
30
+      type: DataTypes.BIGINT,
31
+      allowNull: false,
32
+      defaultValue: 0
33
+    }
34
+  }, {
35
+    sequelize,
36
+    timestamps: false,
37
+  });
38
+};

+ 27
- 0
models/wp_termmeta.js Просмотреть файл

@@ -0,0 +1,27 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_termmeta', {
4
+    meta_id: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    term_id: {
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      defaultValue: 0
14
+    },
15
+    meta_key: {
16
+      type: DataTypes.STRING(255),
17
+      allowNull: true
18
+    },
19
+    meta_value: {
20
+      type: DataTypes.TEXT,
21
+      allowNull: true
22
+    }
23
+  }, {
24
+    sequelize,
25
+    timestamps: false,
26
+  });
27
+};

+ 29
- 0
models/wp_terms.js Просмотреть файл

@@ -0,0 +1,29 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_terms', {
4
+    term_id: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    name: {
11
+      type: DataTypes.STRING(200),
12
+      allowNull: false,
13
+      defaultValue: ""
14
+    },
15
+    slug: {
16
+      type: DataTypes.STRING(200),
17
+      allowNull: false,
18
+      defaultValue: ""
19
+    },
20
+    term_group: {
21
+      type: DataTypes.BIGINT,
22
+      allowNull: false,
23
+      defaultValue: 0
24
+    }
25
+  }, {
26
+    sequelize,
27
+    timestamps: false,
28
+  });
29
+};

+ 27
- 0
models/wp_usermeta.js Просмотреть файл

@@ -0,0 +1,27 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_usermeta', {
4
+    umeta_id: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    user_id: {
11
+      type: DataTypes.BIGINT.UNSIGNED,
12
+      allowNull: false,
13
+      defaultValue: 0
14
+    },
15
+    meta_key: {
16
+      type: DataTypes.STRING(255),
17
+      allowNull: true
18
+    },
19
+    meta_value: {
20
+      type: DataTypes.TEXT,
21
+      allowNull: true
22
+    }
23
+  }, {
24
+    sequelize,
25
+    timestamps: false,
26
+  });
27
+};

+ 59
- 0
models/wp_users.js Просмотреть файл

@@ -0,0 +1,59 @@
1
+const Sequelize = require('sequelize');
2
+module.exports = function(sequelize, DataTypes) {
3
+  return sequelize.define('wp_users', {
4
+    ID: {
5
+      autoIncrement: true,
6
+      type: DataTypes.BIGINT.UNSIGNED,
7
+      allowNull: false,
8
+      primaryKey: true
9
+    },
10
+    user_login: {
11
+      type: DataTypes.STRING(60),
12
+      allowNull: false,
13
+      defaultValue: ""
14
+    },
15
+    user_pass: {
16
+      type: DataTypes.STRING(255),
17
+      allowNull: false,
18
+      defaultValue: ""
19
+    },
20
+    user_nicename: {
21
+      type: DataTypes.STRING(50),
22
+      allowNull: false,
23
+      defaultValue: ""
24
+    },
25
+    user_email: {
26
+      type: DataTypes.STRING(100),
27
+      allowNull: false,
28
+      defaultValue: ""
29
+    },
30
+    user_url: {
31
+      type: DataTypes.STRING(100),
32
+      allowNull: false,
33
+      defaultValue: ""
34
+    },
35
+    user_registered: {
36
+      type: DataTypes.DATE,
37
+      allowNull: false,
38
+      defaultValue: "0000-00-00 00:00:00"
39
+    },
40
+    user_activation_key: {
41
+      type: DataTypes.STRING(255),
42
+      allowNull: false,
43
+      defaultValue: ""
44
+    },
45
+    user_status: {
46
+      type: DataTypes.INTEGER,
47
+      allowNull: false,
48
+      defaultValue: 0
49
+    },
50
+    display_name: {
51
+      type: DataTypes.STRING(250),
52
+      allowNull: false,
53
+      defaultValue: ""
54
+    }
55
+  }, {
56
+    sequelize,
57
+    timestamps: false,
58
+  });
59
+};

+ 3199
- 0
package-lock.json
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 28
- 0
package.json Просмотреть файл

@@ -0,0 +1,28 @@
1
+{
2
+  "name": "movingco",
3
+  "version": "1.0.0",
4
+  "description": "using umzug to grab rows from databases and save them somewhere else",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "get": "npx sequelize-auto -t process.env.TARGET_TABLE -h process.env.TARGET_HOST -p process.env.TARGET_PORT -d process.env.TARGET_DB -u process.env.TARGET_U -x process.env.TARGET_PW -e process.env.TARGET_DIALECT -o './models' -l es6",
8
+    "migrate": "node ./",
9
+    "load": "docker exec -i scratch-mariadb mysql -uroot -proot --database=unclean < dump.sql",
10
+    "test": "echo \"Error: no test specified\" && exit 1"
11
+  },
12
+  "keywords": [
13
+    "umzug",
14
+    "sequalize",
15
+    "sql"
16
+  ],
17
+  "author": "TOJ",
18
+  "license": "UNLICENSED",
19
+  "dependencies": {
20
+    "dotenv": "^8.2.0",
21
+    "mariadb": "^2.5.3",
22
+    "mysql2": "^2.2.5",
23
+    "sequelize": "^6.6.2",
24
+    "sequelize-auto": "^0.8.1",
25
+    "sqlite3": "^5.0.2",
26
+    "umzug": "^2.3.0"
27
+  }
28
+}

Загрузка…
Отмена
Сохранить