Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
content-item-datasource companion PR (#425)
Browse files Browse the repository at this point in the history
* Keep track of changes needed for postgres content-item datasource

* Most recent changes

* Add followings bridge code

* Update tempalte

* Added some documentation around changes

* Fix linter

* Update config

* Update migration help file

* Split config.yml

Co-authored-by: Michael Neeley <micneeley14@gmail.com>
  • Loading branch information
vinnyjth and redreceipt authored Jul 21, 2021
1 parent 123d4a3 commit bb2bf15
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 20 deletions.
61 changes: 61 additions & 0 deletions CONTENT_SHOVEL_MIGRATIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Content Shovel Migration Steps

Migrating Content from being pulled directly from Rock to being pulled via the shovel is a one time process. Depending on the level of customization of your API, it may be time consuming, but overall will result in far greater stability and maintainability.

Listed below are a number of steps you may have to take in order to complete the migration.

## Understanding Core API changes

Moving all the content item data to Postgres comes with some rethinking of how the Content Item data is structured. Here are some of the important changes.

Personas are now tags (with `type: persona`). Content Items can have tags, and people can have tags.

Content items now have a `parentId`

Content items have a `coverImageId`, pointing at their cover image.

ApollosIDs (what you see come through GraphQL) are now stored directly on the content item table.

Features are now a row in the Features table. The entire configuration for the feature is no longer stored in the ID. (Right now this is only true for Content Item features.)

A lot of the ContentItem.dataSource methods have been renamed or changed. In general, a lot more data is available on the ContentItem objects themselves (example - `contentItem.getCoverImage()` vs `ContentItemDataSource.getCoverImage(contentItem)`) but a lot of methods have been aliased to ease the transition.

The request builder is no more. You will want to read up on Sequelize query syntax. Most `getByXXX` methods take a `args` argument that lets you pass filters, eager loads, etc.

*Important*. You can't spread the objects returned by Sequelize methods. For example, if you have a an `item` returned by `getFromId()` doing `{ ...item, attribute: value }` will cause problems.



## Move Typename Configuration to the Shovel.

Moving forward, typenames are pre-determined for content items. The API no longer has to decide what type an item is, that information is stored in the shovel. You'll need to create a new Variable in your Airflow instance storing your typename configuration. The form is a subset of the previous config.yml format. Example below

```json
{
"CONTENT_MAPPINGS": {
"ContentSeriesContentItem": {
"ContentChannelTypeId": [
6
]
},
"DevotionalContentItem": {
"ContentChannelId": [
7
]
},
"WeekendContentItem": {
"ContentChannelId": [
5
]
}
}
}
```

## Update Action Algorithm ID references

Once you have the shovel up and running, you'll want to connect to it via your favorite postgres client. Inside your `config.yml`, you'll want to replace references to the Rock integer IDS with the new Postgres UUIDs. This is easily done, by cross referencing the Integer IDs with the Postgres Database, and then copying in the appropriate UUIDS. You'll find the "ContentChannelItems" in the "contentChannel" table, and the "ContentChannel"s in the "ContentItemsCategory" table.

When using `relatedNodes`, you will want to use the apollosId field instead of the `id` field.


240 changes: 240 additions & 0 deletions apollos-church-api/config.postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
# This file, in conjuction with your .env file,
# should be used to configure the apollos server.

# Any values you wish to keep secret should be placed in `.env`
# You can access those values (and any other values in your environment)
# using the ${VARIABLE_NAME} syntax

# This file should be checked into version control.
# `.env` should NOT be checked into version control.
APP:
# This variable is used for generating deep links.
# It should match whatver is in your Info.plist `CFBundleURLTypes`
DEEP_LINK_HOST: ${DEEP_LINK_HOST}
UNIVERSAL_LINK_HOST: ${UNIVERSAL_LINK_HOST}
ROOT_API_URL: ${ROOT_URL}
JOBS_USERNAME: ${JOBS_USERNAME}
JOBS_PASSWORD: ${JOBS_PASSWORD}
DATABASE:
URL: ${DATABASE_URL}
BUGSNAG:
API_KEY: ${BUGSNAG_KEY}
ROCK:
URL: ${ROCK_URL}
API_TOKEN: ${ROCK_TOKEN}
UNIVERSAL_LINKS:
APPLE_APP_ID: ${APPLE_APP_ID}
APPLE_TEAM_ID: ${APPLE_TEAM_ID}
APP_STORE_LINK: ${IOS_REDIRECT}
PLAY_STORE_LINK: ${ANDROID_REDIRECT}
GOOGLE_APP_ID: ${GOOGLE_APP_ID}
GOOGLE_KEYSTORE_SHA256: ${GOOGLE_KEYSTORE_SHA256}
ONE_SIGNAL:
APP_ID: ${ONE_SIGNAL_APP_ID}
REST_KEY: ${ONE_SIGNAL_REST_KEY}
CHURCH_ONLINE:
URL: ${CHURCH_ONLINE_URL}
WEB_VIEW_URL: https://apollos.online.church/
ALGOLIA:
APPLICATION_ID: ${ALGOLIASEARCH_APPLICATION_ID}
API_KEY: ${ALGOLIASEARCH_API_KEY}
TWILIO:
ACCOUNT_SID: ${TWILIO_ACCOUNT_SID}
AUTH_TOKEN: ${TWILIO_AUTH_TOKEN}
FROM_NUMBER: ${TWILIO_FROM_NUMBER}
PASS:
TEMPLATES:
CHECKIN: ${PWD}/wallet-passes/checkin.pass
CERTIFICATES:
WWDR: ${PASS_WWDR_CERT}
SIGNER_CERT: ${PASS_SIGNER_CERT}
SIGNER_KEY: ${PASS_SIGNER_KEY}
SIGNER_KEY_PASSPHRASE: ${PASS_SIGNER_PASSPHRASE}
BIBLE_API:
KEY: ${BIBLE_API_KEY}
BIBLE_ID:
WEB: '9879dbb7cfe39e4d-01'
KJV: 'de4e12af7f28f599-02'
CLOUDINARY:
URL: ${CLOUDINARY_URL}

CONTENT:
SERMON_CHANNEL_ID: cbc0994a-97f1-471a-a7d5-4eff59d8a389
TYPES:
- ContentSeriesContentItem
- DevotionalContentItem
- MediaContentItem
- UniversalContentItem
- WeekendContentItem
- ContentItem


TABS:
HOME:
- type: ActionBar
title: Welcome to Apollos
actions:
[
{
title: Check In,
icon: check,
action: OPEN_URL,
relatedNode: { __typename: Url, url: 'https://www.google.com' },
},
]
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- c7f43eb9-2200-4267-ab28-871e0d5e785f
- 3dfe7149-136b-4134-bd91-fdd935ef2221
type: HeroList
primaryAction:
# Right now, you hardcode exactly what GraphQL should return.
# Long term, we hope to have a more sophisticated mechanism for driving this field
action: OPEN_NODE
title: 'Read More'
relatedNode:
__typename: UniversalContentItem
id: a2c42d1d-98c8-46fb-aeea-603bc569cf7d
- algorithms: [DAILY_PRAYER]
isCard: false
type: PrayerList
title: Daily Prayer
- algorithms:
- type: CAMPAIGN_ITEMS
channelIds:
- 4b23ebc9-248e-4092-99f9-8829e1b6f1cc
type: HeroList
isFeatured: true
subtitle: Featured
- title: FOR YOU
algorithms: [SERMON_CHILDREN, PERSONA_FEED]
subtitle: Explore what God calls you to today
type: ActionList
- algorithms: [SERIES_IN_PROGRESS]
subtitle: Continue
type: HorizontalCardList
- title: RECOMMENDED
algorithms: [SERMON_CHILDREN]
subtitle: For Him
type: VerticalCardList
- title: BULLETIN
subtitle: What's happening at apollos?
type: ActionList
algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- 13
- type: UPCOMING_EVENTS

READ:
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- c7f43eb9-2200-4267-ab28-871e0d5e785f
limit: 3
type: HorizontalCardList
subtitle: Podcast Messages
primaryAction:
action: OPEN_CHANNEL
title: 'Read More'
relatedNode:
__typename: ContentChannel
apollosId: ContentChannel:f4a5890c-4af5-4d9f-afe3-5d1c6aa85419
title: Podcast Messages
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- d9da719f-84ef-4cf0-9875-22fea4bf09eb
limit: 3
type: HorizontalCardList
subtitle: Devotionals
primaryAction:
action: OPEN_CHANNEL
title: 'Read More'
relatedNode:
__typename: ContentChannel
apollosId: ContentChannel:d9da719f-84ef-4cf0-9875-22fea4bf09eb
title: Devotionals

WATCH:
- algorithms:
- type: LATEST_SERIES_CHILDREN
arguments:
channelId: 8f0a93f5-ccec-4cc1-8fd8-06afe5982f7b
type: HeroList
title: Catch up
subtitle: Latest Series
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- f4a5890c-4af5-4d9f-afe3-5d1c6aa85419
type: VerticalCardList
subtitle: All series
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- 8f0a93f5-ccec-4cc1-8fd8-06afe5982f7b
limit: 3
type: HorizontalCardList
subtitle: Sermons
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- f4a5890c-4af5-4d9f-afe3-5d1c6aa85419
limit: 3
type: HorizontalCardList
subtitle: Podcasts
primaryAction:
action: OPEN_CHANNEL
title: 'Read More'
relatedNode:
__typename: ContentChannel
apollosId: ContentChannel:f4a5890c-4af5-4d9f-afe3-5d1c6aa85419
title: Podcasts
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- f4a5890c-4af5-4d9f-afe3-5d1c6aa85419
limit: 3
type: HorizontalCardList
title: Videos
primaryAction:
action: OPEN_CHANNEL
title: 'Read More'
relatedNode:
__typename: ContentChannel
apollosId: ContentChannel:f4a5890c-4af5-4d9f-afe3-5d1c6aa85419
title: Videos

PRAY:
- algorithms: [DAILY_PRAYER]
isCard: false
type: PrayerList
title: Daily Prayer
- type: VerticalPrayerList
title: Your Prayers
CONNECT:
- type: ActionTable
title: Connect to Apollos
actions:
[
{
title: Google,
action: OPEN_URL,
relatedNode: { __typename: Url, url: 'https://www.google.com' },
},
{
title: Facebook,
action: OPEN_URL,
relatedNode: { __typename: Url, url: 'https://www.facebook.com' },
},
]
2 changes: 1 addition & 1 deletion apollos-church-api/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,4 @@ TABS:
action: OPEN_URL,
relatedNode: { __typename: Url, url: 'https://www.facebook.com' },
},
]
]
6 changes: 5 additions & 1 deletion apollos-church-api/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import fetch from 'node-fetch';
import dotenv from "dotenv/config"; // eslint-disable-line
import ApollosConfig from '@apollosproject/config';

const configName = process.env.DATABASE_URL
? 'config.postgres.yml'
: 'config.yml';

ApollosConfig.loadYaml({
configPath: path.join(__dirname, '..', 'config.yml'),
configPath: path.join(__dirname, '..', configName),
});

// defaults
Expand Down
Loading

0 comments on commit bb2bf15

Please sign in to comment.