Skip to content

Commit

Permalink
Merge pull request #3930 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v4.30.0 part 1
  • Loading branch information
gary02 authored May 22, 2024
2 parents 2bfc79a + e31a441 commit 5d015c9
Show file tree
Hide file tree
Showing 361 changed files with 13,023 additions and 10,241 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ MATTERS_CLOUDFLARE_ACCOUNT_ID=
MATTERS_CLOUDFLARE_ACCOUNT_HASH=
MATTERS_CLOUDFLARE_API_TOKEN=
MATTERS_CLOUDFLARE_TURNSTILE_SECRET_KEY=
MATTERS_VERIFY_CAPTCHA_TOKENS_THRESHOLDS="[0.5, 1.0]"

# to be replaced by sns/sqs fanout mode in next release
MATTERS_AWS_IPFS_ARTICLES_QUEUE_URL="https://sqs.ap-southeast-1.amazonaws.com/903380195283/my-queue.fifo"
Expand Down Expand Up @@ -68,7 +67,6 @@ MATTERS_LIKECOIN_PAY_LIKER_ID=developer
MATTERS_LIKECOIN_PAY_WEBHOOK_SECRET=
MATTERS_TRANSLATE_CREDENTIAL_PATH=.ebextensions/translate-credentials.local.json
MATTERS_GCP_PROJECT_ID=matters-2dd78
MATTERS_RECAPTCHA_KEY=
MATTERS_STRIPE_SECRET=
MATTERS_STRIPE_WEBHOOK_SECRET=
MATTERS_STRIPE_CONNECT_WEBHOOK_SECRET=
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.eslintrc.js
src/definitions/schema.d.ts
build/*
**/__test__/*
29 changes: 27 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
types:
- closed

concurrency:
group: ${{ github.workflow }}-${{ github.base_ref }}
cancel-in-progress: true

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down Expand Up @@ -51,14 +55,14 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'

- name: Cache NPM dependencies
uses: actions/cache@v3
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}
key: ${{ runner.os }}-v18-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Install Dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -129,6 +133,27 @@ jobs:
# === [END] predeploy ===

# === `develop` branch ===
- name: Start VPN (develop)
if: github.base_ref == 'develop'
run: |
sudo apt-get update \
&& sudo apt-get install openvpn \
&& echo $VPN_AUTH | base64 -d > $VPN_AUTH_PATH \
&& echo $VPN_CONFIG | base64 -d > $VPN_CONFIG_PATH \
&& sudo openvpn --config $VPN_CONFIG_PATH --auth-user-pass $VPN_AUTH_PATH --daemon \
&& sleep 15s
env:
VPN_CONFIG: ${{ secrets.DEVELOP_VPN_CONFIG }}
VPN_CONFIG_PATH: '.github/config.ovpn'
VPN_AUTH: ${{ secrets.DEVELOP_VPN_AUTH }}
VPN_AUTH_PATH: '.github/auth.txt'

- name: Check DB Connection
if: github.base_ref == 'develop'
run: nc -zv -w 5 $MATTERS_PG_HOST 5432
env:
MATTERS_PG_HOST: ${{ secrets.DEVELOP_PG_HOST }}

- name: DB Migration (develop)
if: github.base_ref == 'develop'
run: npm run db:migrate
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'

- name: Get Version
id: version
Expand All @@ -36,7 +36,7 @@ jobs:
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}
key: ${{ runner.os }}-v18-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Install Dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'

- name: Cache NPM dependencies
uses: actions/cache@v3
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}
key: ${{ runner.os }}-v18-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Install Dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
Expand All @@ -63,6 +63,7 @@ jobs:
- name: Test
run: npm run test
env:
NODE_OPTIONS: "--no-experimental-fetch"
CODECOV_TOKEN: de5ab681-0837-4a24-b614-0a29225a7e4c
MATTERS_ENV: test
MATTERS_LOGGING_LEVEL: warn
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*.rdb
*.log
*~
tags

yarn.lock
node_modules
Expand Down
12 changes: 7 additions & 5 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"TagOSS": "./tag#Tag",
"Collection": "./collection#Collection",
"Comment": "./comment#Comment",
"Article": "./draft#Draft",
"ArticleAccess": "./draft#Draft",
"ArticleOSS": "./draft#Draft",
"ArticleContents": "./draft#Draft",
"Article": "./article#Article",
"ArticleAccess": "./article#Article",
"ArticleOSS": "./article#Article",
"ArticleVersion": "./article#ArticleVersion",
"ArticleContents": "./article#ArticleVersion",
"Draft": "./draft#Draft",
"DraftAccess": "./draft#Draft",
"Circle": "./circle#Circle",
Expand Down Expand Up @@ -62,7 +63,8 @@
"OfficialAnnouncementNotice": "./notification#NoticeItem",
"Appreciation": "./appreciation#Appreciation",
"OAuthClient": "./user#OAuthClientDB",
"Topic": "./topic#Topic"
"Report": "./report#Report",
"IcymiTopic": "./misc#MattersChoiceTopic"
},
"contextType": "./index#Context",
"makeResolverTypeCallable": true,
Expand Down
28 changes: 28 additions & 0 deletions db/migrations/20231221154057_alter_report_add_reason.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const table = {
report: 'report',
report_asset: 'report_asset',
}

exports.up = async (knex) => {
await knex.schema.dropTable(table.report_asset)
await knex.table(table.report).delete()
await knex.schema.table(table.report, function (t) {
t.enu('reason', [
'tort',
'illegal_advertising',
'discrimination_insult_hatred',
'pornography_involving_minors',
'other',
]).notNullable()
t.dropColumn('category')
t.renameColumn('user_id', 'reporter_id')
})
}

exports.down = async (knex) => {
await knex.schema.table(table.report, function (t) {
t.string('category').notNullable()
t.dropColumn('reason')
t.renameColumn('reporter_id', 'user_id')
})
}
83 changes: 83 additions & 0 deletions db/migrations/20240126160530_migrate_article_versioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const { baseDown } = require('../utils')

const articleTable = 'article'
const articleContentTable = 'article_content'
const articleVersionTable = 'article_version'

exports.up = async (knex) => {
// schema migration

// create new tables, add new columns to article table
await knex('entity_type').insert({ table: articleContentTable })
await knex.schema.createTable(articleContentTable, (t) => {
t.bigIncrements('id').primary()
t.text('content').notNullable()
t.string('hash').notNullable().unique()
t.timestamp('created_at').defaultTo(knex.fn.now())
})

await knex('entity_type').insert({ table: articleVersionTable })
await knex.schema.createTable(articleVersionTable, (t) => {
t.bigIncrements('id').primary()
t.bigInteger('article_id').unsigned().notNullable()
t.string('title').notNullable()
t.bigInteger('cover').unsigned()
t.string('summary').notNullable()
t.boolean('summary_customized').notNullable()
t.bigInteger('content_id').unsigned().notNullable()
t.bigInteger('content_md_id').unsigned()
t.specificType('tags', 'text ARRAY').notNullable()
t.specificType('connections', 'text ARRAY').notNullable()
t.integer('word_count').notNullable()
t.string('data_hash')
t.string('media_hash')
t.string('language')
t.bigInteger('circle_id').unsigned()
t.enu('access', ['public', 'paywall']).notNullable()
t.enu('license', [
'cc_0',
'cc_by_nc_nd_2',
'cc_by_nc_nd_4',
'arr',
]).notNullable()
t.string('iscn_id')
t.string('request_for_donation')
t.string('reply_to_donator')
t.boolean('can_comment').notNullable()
t.boolean('sensitive_by_author').notNullable()
t.text('description')
t.timestamp('created_at').defaultTo(knex.fn.now())
t.timestamp('updated_at').defaultTo(knex.fn.now())

t.foreign('cover').references('id').inTable('asset')
t.foreign('article_id').references('id').inTable('article')
t.foreign('circle_id').references('id').inTable('circle')

t.index('article_id')
t.index(['article_id', 'id'])
t.index('data_hash')
t.index('media_hash')
t.index('iscn_id')
t.index('title')
})
await knex.schema.alterTable(articleTable, (t) => {
t.boolean('sensitive_by_admin').notNullable().defaultTo(false)
t.setNullable('uuid')
t.setNullable('title')
t.setNullable('slug')
t.setNullable('content')
t.setNullable('summary')
t.setNullable('word_count')
})
await knex.schema.alterTable('draft', (t) => {
t.setNullable('uuid')
})
}

exports.down = async (knex) => {
await baseDown(articleVersionTable)(knex)
await baseDown(articleContentTable)(knex)
await knex.schema.alterTable(articleTable, (t) => {
t.dropColumn('sensitive_by_admin')
})
}
104 changes: 104 additions & 0 deletions db/migrations/20240126160531_migrate_article_versioning_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
exports.up = async (knex) => {
// data migration

// migrate data from draft to article_content, article_version
await knex.schema.raw(`
DO $$
DECLARE
draft_record RECORD;
content_hash TEXT;
content_id BIGINT;
content_md_hash TEXT;
content_md_id BIGINT;
article_version_id BIGINT;
BEGIN
RAISE NOTICE 'start data migration';
FOR draft_record IN
SELECT * FROM draft WHERE article_id IS NOT NULL AND publish_state='published' ORDER BY id
LOOP
RAISE NOTICE ' processing draft %', draft_record.id;
-- get content_id, content_md_id
content_hash := md5(COALESCE (draft_record.content, ''));
SELECT id INTO content_id FROM article_content WHERE hash = content_hash;
IF NOT FOUND THEN
INSERT INTO article_content (content, hash) VALUES (COALESCE (draft_record.content, ''), content_hash) RETURNING id into content_id;
END IF;
RAISE NOTICE ' content_id %', content_id;
content_md_hash := md5(draft_record.content_md);
IF content_md_hash IS NULL THEN
content_md_id := NULL;
ELSE
SELECT id INTO content_md_id FROM article_content WHERE hash = content_md_hash;
IF NOT FOUND THEN
INSERT INTO article_content (content, hash) VALUES (draft_record.content_md, content_md_hash) RETURNING id into content_md_id;
END IF;
END IF;
RAISE NOTICE ' content_md_id %', content_md_id;
-- insert article_version table
INSERT INTO article_version (
article_id,
title,
cover,
summary,
summary_customized,
content_id,
content_md_id,
tags,
connections,
word_count,
data_hash,
media_hash,
language,
circle_id,
access,
license,
iscn_id,
request_for_donation,
reply_to_donator,
can_comment,
sensitive_by_author,
created_at,
updated_at
) VALUES (
draft_record.article_id,
draft_record.title,
draft_record.cover,
COALESCE (draft_record.summary, ''),
draft_record.summary_customized,
content_id,
content_md_id,
COALESCE (draft_record.tags, '{}'),
COALESCE (draft_record.collection, '{}'),
COALESCE (draft_record.word_count, 0),
draft_record.data_hash,
draft_record.media_hash,
draft_record.language,
draft_record.circle_id,
draft_record.access,
draft_record.license,
draft_record.iscn_id,
draft_record.request_for_donation,
draft_record.reply_to_donator,
draft_record.can_comment,
draft_record.sensitive_by_author,
draft_record.created_at,
draft_record.updated_at
) RETURNING id INTO article_version_id;
RAISE NOTICE ' article_version_id %', article_version_id;
IF draft_record.sensitive_by_admin = true THEN
UPDATE article SET sensitive_by_admin = true WHERE id = draft_record.article_id;
END IF;
END LOOP;
END
$$;
`)
}

exports.down = () => {
// do nothing
}
Loading

0 comments on commit 5d015c9

Please sign in to comment.