From ba4f8cc857ef9cfa3f47f9bdb16b59c18cc9b806 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Fri, 23 Apr 2021 11:24:25 +0200 Subject: [PATCH] Added OAuth user data issue https://github.com/TryGhost/Team/issues/614 - This allows keeping each user oauth data, to compare on future logins --- core/server/data/exporter/table-lists.js | 1 + .../versions/4.11/01-add-oauth-user-data.js | 12 ++++++++++++ core/server/data/schema/schema.js | 10 ++++++++++ test/regression/exporter/exporter.test.js | 1 + test/unit/data/schema/integrity.test.js | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 core/server/data/migrations/versions/4.11/01-add-oauth-user-data.js diff --git a/core/server/data/exporter/table-lists.js b/core/server/data/exporter/table-lists.js index 7fd52a719a..3288be9f6d 100644 --- a/core/server/data/exporter/table-lists.js +++ b/core/server/data/exporter/table-lists.js @@ -14,6 +14,7 @@ const BACKUP_TABLES = [ 'members_stripe_customers_subscriptions', 'migrations', 'migrations_lock', + 'oauth', 'permissions', 'permissions_roles', 'permissions_users', diff --git a/core/server/data/migrations/versions/4.11/01-add-oauth-user-data.js b/core/server/data/migrations/versions/4.11/01-add-oauth-user-data.js new file mode 100644 index 0000000000..db6421c98b --- /dev/null +++ b/core/server/data/migrations/versions/4.11/01-add-oauth-user-data.js @@ -0,0 +1,12 @@ +const {addTable} = require('../../utils'); + +module.exports = addTable('oauth', { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + provider: {type: 'string', maxlength: 50, nullable: false}, + provider_id: {type: 'string', maxlength: 191, nullable: false}, + access_token: {type: 'text', maxlength: 65535, nullable: true}, + refresh_token: {type: 'text', maxlength: 2000, nullable: true}, + created_at: {type: 'dateTime', nullable: false}, + updated_at: {type: 'dateTime', nullable: true}, + user_id: {type: 'string', maxlength: 24, nullable: false, references: 'users.id'} +}); diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index 136eb9f966..92abcf0c81 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -112,6 +112,16 @@ module.exports = { updated_at: {type: 'dateTime', nullable: true}, updated_by: {type: 'string', maxlength: 24, nullable: true} }, + oauth: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + provider: {type: 'string', maxlength: 50, nullable: false}, + provider_id: {type: 'string', maxlength: 191, nullable: false}, + access_token: {type: 'text', maxlength: 65535, nullable: true}, + refresh_token: {type: 'text', maxlength: 2000, nullable: true}, + created_at: {type: 'dateTime', nullable: false}, + updated_at: {type: 'dateTime', nullable: true}, + user_id: {type: 'string', maxlength: 24, nullable: false, references: 'users.id'} + }, posts_authors: { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id'}, diff --git a/test/regression/exporter/exporter.test.js b/test/regression/exporter/exporter.test.js index f325aacd94..c160fcbc54 100644 --- a/test/regression/exporter/exporter.test.js +++ b/test/regression/exporter/exporter.test.js @@ -45,6 +45,7 @@ describe('Exporter', function () { 'migrations', 'migrations_lock', 'mobiledoc_revisions', + 'oauth', 'permissions', 'permissions_roles', 'permissions_users', diff --git a/test/unit/data/schema/integrity.test.js b/test/unit/data/schema/integrity.test.js index 50015ba0a0..10bb7c9dc6 100644 --- a/test/unit/data/schema/integrity.test.js +++ b/test/unit/data/schema/integrity.test.js @@ -32,7 +32,7 @@ const defaultSettings = require('../../../../core/server/data/schema/default-set */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = '32e92f2cf2874d6d8ac68bfdc97cd885'; + const currentSchemaHash = 'a2248eaa72a9d08c3753b90a9436dbe3'; const currentFixturesHash = '97283c575b1f6c84c27db6e1b1be21d4'; const currentSettingsHash = 'dd0a0a08e66b252e7704bb7e346a8c20'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';