From 4f61b53fe9fe28b4fe3b9c549cbf78b32a24c998 Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Thu, 6 Jun 2019 17:35:20 -0400 Subject: [PATCH 1/9] Adds migration scripts to add new columns --- services/migrations/005_add_published_at_column.sql | 10 ++++++++++ services/migrations/006_add_unpublished_at_column.sql | 2 ++ services/migrations/007_add_archived_at_column.sql | 2 ++ services/migrations/008_add_republished_at_column.sql | 2 ++ 4 files changed, 16 insertions(+) create mode 100644 services/migrations/005_add_published_at_column.sql create mode 100644 services/migrations/006_add_unpublished_at_column.sql create mode 100644 services/migrations/007_add_archived_at_column.sql create mode 100644 services/migrations/008_add_republished_at_column.sql diff --git a/services/migrations/005_add_published_at_column.sql b/services/migrations/005_add_published_at_column.sql new file mode 100644 index 0000000..99158ee --- /dev/null +++ b/services/migrations/005_add_published_at_column.sql @@ -0,0 +1,10 @@ +ALTER TABLE IF EXISTS pages +ADD COLUMN IF NOT EXISTS published_at TIMESTAMPTZ; + +UPDATE pages +SET published_at = subquery.first_publish_time +FROM (SELECT id, TO_TIMESTAMP(meta ->> 'firstPublishTime', 'YYYY-MM-DD HH24:MI:SSZ') as first_publish_time + FROM pages + WHERE meta IS NOT NULL + AND meta ->> 'firstPublishTime' IS NOT NULL) AS subquery +WHERE pages.id = subquery.id; diff --git a/services/migrations/006_add_unpublished_at_column.sql b/services/migrations/006_add_unpublished_at_column.sql new file mode 100644 index 0000000..2430dfa --- /dev/null +++ b/services/migrations/006_add_unpublished_at_column.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS pages +ADD COLUMN IF NOT EXISTS unpublished_at TIMESTAMPTZ; diff --git a/services/migrations/007_add_archived_at_column.sql b/services/migrations/007_add_archived_at_column.sql new file mode 100644 index 0000000..e62ca04 --- /dev/null +++ b/services/migrations/007_add_archived_at_column.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS pages +ADD COLUMN IF NOT EXISTS archived_at TIMESTAMPTZ; diff --git a/services/migrations/008_add_republished_at_column.sql b/services/migrations/008_add_republished_at_column.sql new file mode 100644 index 0000000..231c224 --- /dev/null +++ b/services/migrations/008_add_republished_at_column.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS pages +ADD COLUMN IF NOT EXISTS republished_at TIMESTAMPTZ; From 28a9e7182a6f199bdcfcb94e5c31cb516c71cbfe Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Fri, 14 Jun 2019 17:56:38 -0400 Subject: [PATCH 2/9] Modifies putMeta to handle publish events columns --- postgres/client.js | 36 +++++++++++++++++-- postgres/client.test.js | 21 +++++++++++ .../006_add_unpublished_at_column.sql | 12 +++++++ .../migrations/007_add_archived_at_column.sql | 12 +++++++ .../008_add_republished_at_column.sql | 8 +++++ 5 files changed, 86 insertions(+), 3 deletions(-) diff --git a/postgres/client.js b/postgres/client.js index 3d55edb..f9cc5c0 100644 --- a/postgres/client.js +++ b/postgres/client.js @@ -5,7 +5,7 @@ const { POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, POSTGRES { parseOrNot, wrapInObject, decode } = require('../services/utils'), { findSchemaAndTable, wrapJSONStringInObject } = require('../services/utils'), knexLib = require('knex'), - { isList, isUri } = require('clayutils'), + { isList, isUri, isPage } = require('clayutils'), TransformStream = require('../services/list-transform-stream'), META_PUT_PATCH_FN = patch('meta'); var knex, log = require('../services/log').setup({ file: __filename }); @@ -272,12 +272,42 @@ function getMeta(key) { * @param {Object} value [description] * @return {Promise} [description] */ +/* eslint complexity: 0 */ function putMeta(key, value) { const { schema, table } = findSchemaAndTable(key), - map = columnToValueMap('id', key); + map = columnToValueMap('id', key), + parsedValue = parseOrNot(value); // add meta column to map - columnToValueMap('meta', parseOrNot(value), map); + columnToValueMap('meta', parsedValue, map); + + if (isPage(key)) { + // If value has first publish time add it to the map + if (parsedValue.firstPublishTime) + columnToValueMap('published_at', parsedValue.firstPublishTime, map); + + // If value has publish time add it as republished date + if (parsedValue.publishTime) + columnToValueMap('republished_at', parsedValue.publishTime, map); + + // If we have history data, then find the unpublish and archive events + if (parsedValue.history && parsedValue.history.length) { + const latestUnpublish = parsedValue.history + .filter(event => event.action === 'unpublish') + .pop() || {}, + latestArchived = parsedValue.history + .filter(event => event.action === 'archive') + .pop() || {}; + + if (latestUnpublish.timestamp) + columnToValueMap('unpublished_at', latestUnpublish.timestamp, map); + + if (latestArchived.timestamp) + columnToValueMap('archived_at', latestArchived.timestamp, map); + } + + console.log({map}); + } return onConflictPut(map, schema, table).then(() => map.meta); } diff --git a/postgres/client.test.js b/postgres/client.test.js index 0ce693b..db556eb 100644 --- a/postgres/client.test.js +++ b/postgres/client.test.js @@ -605,6 +605,27 @@ describe('postgres/client', () => { expect(data).toEqual(data); }); }); + + test('if uri is page, insert publication events dates', () => { + const key = 'nymag.com/_pages/sample-page', + meta = { + someText: '', + someOtherText: '', + firstPublishTime: '2019-06-14', + publishTime: '2019-06-14', + history: [{ + action: 'unpublish', + timestamp: '2019-06-14' + }, { + action: 'archive', + timestamp: '2019-06-14' + }] + }; + + return client.putMeta(key, meta).then((data) => { + expect(data).toEqual(meta); + }); + }); }); describe('batch', () => { diff --git a/services/migrations/006_add_unpublished_at_column.sql b/services/migrations/006_add_unpublished_at_column.sql index 2430dfa..b2d175f 100644 --- a/services/migrations/006_add_unpublished_at_column.sql +++ b/services/migrations/006_add_unpublished_at_column.sql @@ -1,2 +1,14 @@ ALTER TABLE IF EXISTS pages ADD COLUMN IF NOT EXISTS unpublished_at TIMESTAMPTZ; + +UPDATE pages +SET unpublished_at = subquery.unpublish_date +FROM (SELECT DISTINCT ON (id) id, + events ->> 'action' AS action, + TO_TIMESTAMP(events ->> 'timestamp', 'YYYY-MM-DD HH24:MI:SSZ') AS unpublish_date + FROM pages AS p, + JSONB_ARRAY_ELEMENTS(p.meta -> 'history') AS events + WHERE meta -> 'history' IS NOT NULL + AND events ->> 'action' = 'unpublish' + ORDER BY id, unpublish_date DESC) AS subquery +WHERE pages.id = subquery.id; diff --git a/services/migrations/007_add_archived_at_column.sql b/services/migrations/007_add_archived_at_column.sql index e62ca04..839a0d0 100644 --- a/services/migrations/007_add_archived_at_column.sql +++ b/services/migrations/007_add_archived_at_column.sql @@ -1,2 +1,14 @@ ALTER TABLE IF EXISTS pages ADD COLUMN IF NOT EXISTS archived_at TIMESTAMPTZ; + +UPDATE pages +SET archived_at = subquery.archive_date +FROM (SELECT DISTINCT ON (id) id, + events ->> 'action' AS action, + TO_TIMESTAMP(events ->> 'timestamp', 'YYYY-MM-DD HH24:MI:SSZ') AS archive_date + FROM pages AS p, + JSONB_ARRAY_ELEMENTS(p.meta -> 'history') AS events + WHERE meta -> 'history' IS NOT NULL + AND events ->> 'action' = 'archive' + ORDER BY id, archive_date DESC) AS subquery +WHERE pages.id = subquery.id; diff --git a/services/migrations/008_add_republished_at_column.sql b/services/migrations/008_add_republished_at_column.sql index 231c224..273b830 100644 --- a/services/migrations/008_add_republished_at_column.sql +++ b/services/migrations/008_add_republished_at_column.sql @@ -1,2 +1,10 @@ ALTER TABLE IF EXISTS pages ADD COLUMN IF NOT EXISTS republished_at TIMESTAMPTZ; + +UPDATE pages +SET published_at = subquery.republish_time +FROM (SELECT id, TO_TIMESTAMP(meta ->> 'publishTime', 'YYYY-MM-DD HH24:MI:SSZ') AS republish_time + FROM pages + WHERE meta IS NOT NULL + AND meta ->> 'publishTime' IS NOT NULL) AS subquery +WHERE pages.id = subquery.id; From c5c4dd10012e4d5db8465ea28353dde981be4377 Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Mon, 17 Jun 2019 12:06:44 -0400 Subject: [PATCH 3/9] Fixes test cases for new changes --- postgres/client.js | 2 -- postgres/client.test.js | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/postgres/client.js b/postgres/client.js index f9cc5c0..ef2e350 100644 --- a/postgres/client.js +++ b/postgres/client.js @@ -305,8 +305,6 @@ function putMeta(key, value) { if (latestArchived.timestamp) columnToValueMap('archived_at', latestArchived.timestamp, map); } - - console.log({map}); } return onConflictPut(map, schema, table).then(() => map.meta); diff --git a/postgres/client.test.js b/postgres/client.test.js index db556eb..d41a1e7 100644 --- a/postgres/client.test.js +++ b/postgres/client.test.js @@ -611,8 +611,6 @@ describe('postgres/client', () => { meta = { someText: '', someOtherText: '', - firstPublishTime: '2019-06-14', - publishTime: '2019-06-14', history: [{ action: 'unpublish', timestamp: '2019-06-14' @@ -626,6 +624,38 @@ describe('postgres/client', () => { expect(data).toEqual(meta); }); }); + + test('if uri is page and does not have history, insert without publication dates', () => { + const key = 'nymag.com/_pages/sample-page', + meta = { + someText: '', + someOtherText: '', + firstPublishTime: '2019-06-14', + publishTime: '2019-06-14' + }; + + return client.putMeta(key, meta).then((data) => { + expect(data).toEqual(meta); + }); + }); + + test('if uri is page, but history does not have unpublish/archive events, insert without those dates', () => { + const key = 'nymag.com/_pages/sample-page', + meta = { + someText: '', + someOtherText: '', + firstPublishTime: '2019-06-14', + publishTime: '2019-06-14', + history: [{ + action: 'create', + timestamp: '2019-06-14' + }] + }; + + return client.putMeta(key, meta).then((data) => { + expect(data).toEqual(meta); + }); + }); }); describe('batch', () => { From 94dd0055db1518978bdbd965c10c263926bd7858 Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Wed, 26 Jun 2019 14:03:06 -0400 Subject: [PATCH 4/9] Applies PR code review feedback --- postgres/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres/client.js b/postgres/client.js index ef2e350..a78fcf3 100644 --- a/postgres/client.js +++ b/postgres/client.js @@ -282,11 +282,11 @@ function putMeta(key, value) { columnToValueMap('meta', parsedValue, map); if (isPage(key)) { - // If value has first publish time add it to the map + // If value has first publish time, add it to the map if (parsedValue.firstPublishTime) columnToValueMap('published_at', parsedValue.firstPublishTime, map); - // If value has publish time add it as republished date + // If value has publish time, add it as republished date if (parsedValue.publishTime) columnToValueMap('republished_at', parsedValue.publishTime, map); From 0c9d2f2af4d4b2129bb48639dd94ef77885b7433 Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Thu, 27 Jun 2019 15:09:43 -0400 Subject: [PATCH 5/9] Modifies migration run time --- postgres/index.js | 34 +++++++++---------- ...mn.sql => 001_add_published_at_column.sql} | 0 .../001_create_components_schema.sql | 1 - ....sql => 002_add_unpublished_at_column.sql} | 0 .../migrations/002_create_layouts_schema.sql | 1 - ...umn.sql => 003_add_archived_at_column.sql} | 0 .../migrations/003_create_pages_table.sql | 1 - ....sql => 004_add_republished_at_column.sql} | 0 services/migrations/004_create_uris_table.sql | 1 - 9 files changed, 16 insertions(+), 22 deletions(-) rename services/migrations/{005_add_published_at_column.sql => 001_add_published_at_column.sql} (100%) delete mode 100644 services/migrations/001_create_components_schema.sql rename services/migrations/{006_add_unpublished_at_column.sql => 002_add_unpublished_at_column.sql} (100%) delete mode 100644 services/migrations/002_create_layouts_schema.sql rename services/migrations/{007_add_archived_at_column.sql => 003_add_archived_at_column.sql} (100%) delete mode 100644 services/migrations/003_create_pages_table.sql rename services/migrations/{008_add_republished_at_column.sql => 004_add_republished_at_column.sql} (100%) delete mode 100644 services/migrations/004_create_uris_table.sql diff --git a/postgres/index.js b/postgres/index.js index 6b7322b..95afd4b 100644 --- a/postgres/index.js +++ b/postgres/index.js @@ -25,7 +25,7 @@ function createRemainingTables() { for (let i = 0; i < DATA_STRUCTURES.length; i++) { let STRUCTURE = DATA_STRUCTURES[i]; - if (STRUCTURE !== 'components' && STRUCTURE !== 'pages' && STRUCTURE !== 'layouts' && STRUCTURE !== 'uris') { + if (STRUCTURE !== 'components' && STRUCTURE !== 'pages' && STRUCTURE !== 'layouts') { promises.push(client.createTable(STRUCTURE)); } } @@ -59,24 +59,22 @@ function setup(testPostgresHost) { } return client.connect() - .then(() => { - return migrate( - { - database: POSTGRES_DB, - user: POSTGRES_USER, - password: POSTGRES_PASSWORD, - host: postgresHost, - port: POSTGRES_PORT - }, - path.join(__dirname, '../services/migrations') - ); - }) - .then(() => { - log('info', 'Migrations Complete'); - }) - .then(() => createTables()) + .then(() => client.createSchema('components')) + .then(() => client.createSchema('layouts')) + .then(createTables) + .then(() => migrate( + { + database: POSTGRES_DB, + user: POSTGRES_USER, + password: POSTGRES_PASSWORD, + host: postgresHost, + port: POSTGRES_PORT + }, + path.join(__dirname, '../services/migrations') + )) + .then(() => log('info', 'Migrations Complete')) .then(() => ({ server: `${postgresHost}:${POSTGRES_PORT}` })) - .catch(logGenericError); + .catch(logGenericError(__filename)); } module.exports.setup = setup; diff --git a/services/migrations/005_add_published_at_column.sql b/services/migrations/001_add_published_at_column.sql similarity index 100% rename from services/migrations/005_add_published_at_column.sql rename to services/migrations/001_add_published_at_column.sql diff --git a/services/migrations/001_create_components_schema.sql b/services/migrations/001_create_components_schema.sql deleted file mode 100644 index 042d10e..0000000 --- a/services/migrations/001_create_components_schema.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE SCHEMA IF NOT EXISTS components; diff --git a/services/migrations/006_add_unpublished_at_column.sql b/services/migrations/002_add_unpublished_at_column.sql similarity index 100% rename from services/migrations/006_add_unpublished_at_column.sql rename to services/migrations/002_add_unpublished_at_column.sql diff --git a/services/migrations/002_create_layouts_schema.sql b/services/migrations/002_create_layouts_schema.sql deleted file mode 100644 index 8a3e1dc..0000000 --- a/services/migrations/002_create_layouts_schema.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE SCHEMA IF NOT EXISTS layouts; diff --git a/services/migrations/007_add_archived_at_column.sql b/services/migrations/003_add_archived_at_column.sql similarity index 100% rename from services/migrations/007_add_archived_at_column.sql rename to services/migrations/003_add_archived_at_column.sql diff --git a/services/migrations/003_create_pages_table.sql b/services/migrations/003_create_pages_table.sql deleted file mode 100644 index 8bb3792..0000000 --- a/services/migrations/003_create_pages_table.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE IF NOT EXISTS "pages" ( id TEXT PRIMARY KEY NOT NULL, data JSONB, meta JSONB ); diff --git a/services/migrations/008_add_republished_at_column.sql b/services/migrations/004_add_republished_at_column.sql similarity index 100% rename from services/migrations/008_add_republished_at_column.sql rename to services/migrations/004_add_republished_at_column.sql diff --git a/services/migrations/004_create_uris_table.sql b/services/migrations/004_create_uris_table.sql deleted file mode 100644 index 2d74761..0000000 --- a/services/migrations/004_create_uris_table.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE IF NOT EXISTS "uris" ( id TEXT PRIMARY KEY NOT NULL, data TEXT NOT NULL, url TEXT ); From c89c677a50d5395a652b958bc42efb4a879b9436 Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Thu, 27 Jun 2019 15:26:55 -0400 Subject: [PATCH 6/9] Adds uris table creation statement --- postgres/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/postgres/index.js b/postgres/index.js index 95afd4b..9dce850 100644 --- a/postgres/index.js +++ b/postgres/index.js @@ -25,7 +25,7 @@ function createRemainingTables() { for (let i = 0; i < DATA_STRUCTURES.length; i++) { let STRUCTURE = DATA_STRUCTURES[i]; - if (STRUCTURE !== 'components' && STRUCTURE !== 'pages' && STRUCTURE !== 'layouts') { + if (STRUCTURE !== 'components' && STRUCTURE !== 'pages' && STRUCTURE !== 'layouts' && STRUCTURE !== 'uris') { promises.push(client.createTable(STRUCTURE)); } } @@ -42,6 +42,7 @@ function createTables() { return bluebird.all(getComponents().map(component => client.createTable(`components.${component}`))) .then(() => bluebird.all(getLayouts().map(layout => client.createTableWithMeta(`layouts.${layout}`)))) .then(() => client.createTableWithMeta('pages')) + .then(() => client.raw('CREATE TABLE IF NOT EXISTS ?? ( id TEXT PRIMARY KEY NOT NULL, data TEXT NOT NULL, url TEXT );', ['uris'])) .then(() => createRemainingTables()); } From 441c20281b89a8838a2f0ca851a41d2a31e8863e Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Thu, 27 Jun 2019 17:14:57 -0400 Subject: [PATCH 7/9] Applies more PR code review feedback --- postgres/client.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/postgres/client.js b/postgres/client.js index a78fcf3..ca0a5df 100644 --- a/postgres/client.js +++ b/postgres/client.js @@ -292,12 +292,8 @@ function putMeta(key, value) { // If we have history data, then find the unpublish and archive events if (parsedValue.history && parsedValue.history.length) { - const latestUnpublish = parsedValue.history - .filter(event => event.action === 'unpublish') - .pop() || {}, - latestArchived = parsedValue.history - .filter(event => event.action === 'archive') - .pop() || {}; + const latestUnpublish = getLatestActionByName(parsedValue.history, 'unpublish'), + latestArchived = getLatestActionByName(parsedValue.history, 'archive'); if (latestUnpublish.timestamp) columnToValueMap('unpublished_at', latestUnpublish.timestamp, map); @@ -310,6 +306,18 @@ function putMeta(key, value) { return onConflictPut(map, schema, table).then(() => map.meta); } +/** + * Gets the latest entry in the history based on the action + * @param {Object[]} history + * @param {String} action + * @returns {Object} + */ +function getLatestActionByName(history, action) { + return history + .filter(event => event.action === action) + .pop() || {}; +} + /** * Creates a table with the name that's * passed into the function. Table has From 65bcd09f8a8f51f086944a71c30b37a546eea2e8 Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Mon, 1 Jul 2019 16:36:36 -0400 Subject: [PATCH 8/9] Fixes typo in republished_at migration script --- services/migrations/004_add_republished_at_column.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/migrations/004_add_republished_at_column.sql b/services/migrations/004_add_republished_at_column.sql index 273b830..d93347e 100644 --- a/services/migrations/004_add_republished_at_column.sql +++ b/services/migrations/004_add_republished_at_column.sql @@ -2,7 +2,7 @@ ALTER TABLE IF EXISTS pages ADD COLUMN IF NOT EXISTS republished_at TIMESTAMPTZ; UPDATE pages -SET published_at = subquery.republish_time +SET republished_at = subquery.republish_time FROM (SELECT id, TO_TIMESTAMP(meta ->> 'publishTime', 'YYYY-MM-DD HH24:MI:SSZ') AS republish_time FROM pages WHERE meta IS NOT NULL From 21c0440e8fc0b93f8f39db07bf27ce9d46764d78 Mon Sep 17 00:00:00 2001 From: Manuel Emilio Urena Date: Fri, 5 Jul 2019 14:44:09 -0400 Subject: [PATCH 9/9] Refactors migration scripts --- services/migrations/001_add_publish_event_columns.sql | 5 +++++ ...ished_at_column.sql => 002_set_unpublished_at_values.sql} | 3 --- ...archived_at_column.sql => 003_set_archived_at_values.sql} | 3 --- ...ished_at_column.sql => 004_set_republished_at_values.sql} | 3 --- ...blished_at_column.sql => 005_set_published_at_values.sql} | 3 --- 5 files changed, 5 insertions(+), 12 deletions(-) create mode 100644 services/migrations/001_add_publish_event_columns.sql rename services/migrations/{002_add_unpublished_at_column.sql => 002_set_unpublished_at_values.sql} (84%) rename services/migrations/{003_add_archived_at_column.sql => 003_set_archived_at_values.sql} (84%) rename services/migrations/{004_add_republished_at_column.sql => 004_set_republished_at_values.sql} (77%) rename services/migrations/{001_add_published_at_column.sql => 005_set_published_at_values.sql} (78%) diff --git a/services/migrations/001_add_publish_event_columns.sql b/services/migrations/001_add_publish_event_columns.sql new file mode 100644 index 0000000..07e0f8d --- /dev/null +++ b/services/migrations/001_add_publish_event_columns.sql @@ -0,0 +1,5 @@ +ALTER TABLE IF EXISTS pages +ADD COLUMN IF NOT EXISTS published_at TIMESTAMPTZ, +ADD COLUMN IF NOT EXISTS unpublished_at TIMESTAMPTZ, +ADD COLUMN IF NOT EXISTS republished_at TIMESTAMPTZ, +ADD COLUMN IF NOT EXISTS archived_at TIMESTAMPTZ; diff --git a/services/migrations/002_add_unpublished_at_column.sql b/services/migrations/002_set_unpublished_at_values.sql similarity index 84% rename from services/migrations/002_add_unpublished_at_column.sql rename to services/migrations/002_set_unpublished_at_values.sql index b2d175f..8191f81 100644 --- a/services/migrations/002_add_unpublished_at_column.sql +++ b/services/migrations/002_set_unpublished_at_values.sql @@ -1,6 +1,3 @@ -ALTER TABLE IF EXISTS pages -ADD COLUMN IF NOT EXISTS unpublished_at TIMESTAMPTZ; - UPDATE pages SET unpublished_at = subquery.unpublish_date FROM (SELECT DISTINCT ON (id) id, diff --git a/services/migrations/003_add_archived_at_column.sql b/services/migrations/003_set_archived_at_values.sql similarity index 84% rename from services/migrations/003_add_archived_at_column.sql rename to services/migrations/003_set_archived_at_values.sql index 839a0d0..6862a91 100644 --- a/services/migrations/003_add_archived_at_column.sql +++ b/services/migrations/003_set_archived_at_values.sql @@ -1,6 +1,3 @@ -ALTER TABLE IF EXISTS pages -ADD COLUMN IF NOT EXISTS archived_at TIMESTAMPTZ; - UPDATE pages SET archived_at = subquery.archive_date FROM (SELECT DISTINCT ON (id) id, diff --git a/services/migrations/004_add_republished_at_column.sql b/services/migrations/004_set_republished_at_values.sql similarity index 77% rename from services/migrations/004_add_republished_at_column.sql rename to services/migrations/004_set_republished_at_values.sql index d93347e..e8ef980 100644 --- a/services/migrations/004_add_republished_at_column.sql +++ b/services/migrations/004_set_republished_at_values.sql @@ -1,6 +1,3 @@ -ALTER TABLE IF EXISTS pages -ADD COLUMN IF NOT EXISTS republished_at TIMESTAMPTZ; - UPDATE pages SET republished_at = subquery.republish_time FROM (SELECT id, TO_TIMESTAMP(meta ->> 'publishTime', 'YYYY-MM-DD HH24:MI:SSZ') AS republish_time diff --git a/services/migrations/001_add_published_at_column.sql b/services/migrations/005_set_published_at_values.sql similarity index 78% rename from services/migrations/001_add_published_at_column.sql rename to services/migrations/005_set_published_at_values.sql index 99158ee..4c24cc8 100644 --- a/services/migrations/001_add_published_at_column.sql +++ b/services/migrations/005_set_published_at_values.sql @@ -1,6 +1,3 @@ -ALTER TABLE IF EXISTS pages -ADD COLUMN IF NOT EXISTS published_at TIMESTAMPTZ; - UPDATE pages SET published_at = subquery.first_publish_time FROM (SELECT id, TO_TIMESTAMP(meta ->> 'firstPublishTime', 'YYYY-MM-DD HH24:MI:SSZ') as first_publish_time