From 8cdc20d490e298a19af662fd20d4ad469887978d Mon Sep 17 00:00:00 2001 From: Kevin Triplett Date: Thu, 14 Nov 2024 12:35:06 -0600 Subject: [PATCH 1/4] update seeds --- apps/backend/seeds/groups.js | 152 ++++++++++++++++++++++++++++++++--- 1 file changed, 139 insertions(+), 13 deletions(-) diff --git a/apps/backend/seeds/groups.js b/apps/backend/seeds/groups.js index 7bc048e056..a5a765ad67 100644 --- a/apps/backend/seeds/groups.js +++ b/apps/backend/seeds/groups.js @@ -1,20 +1,146 @@ 'use strict' exports.seed = function (knex, Promise) { + + // create records to be loaded + const responsibilitiesData = [ + { + title: 'Administration', + description: 'Allows for editing group settings, exporting data, and deleting the group.', + type: 'system' + }, + { + title: 'Add Members', + description: 'The ability to invite and add new people to the group, and to accept or reject join requests.', + type: 'system' + }, + { + title: 'Remove Members', + description: 'The ability to remove a member from the group.', + type: 'system' + }, + { + title: 'Manage Content', + description: 'Adjust group topics, custom views and manage content that contradicts the agreements of the group.', + type: 'system' + } + ] + + const commonRolesData = [ + { + name: 'Coordinator', + description: 'Coordinators are empowered to do everything related to group administration.', + emoji: '🪄' + }, + { + name: 'Moderator', + description: 'Moderators are expected to actively engage in discussion, encourage participation, and take corrective action if a member violates group agreements.', + emoji: '⚖️' + }, + { + name: 'Host', + description: 'Hosts are responsible for cultivating a good atmosphere by welcoming and orienting new members, embodying the group culture and agreements, and helping members connect with relevant content and people.', + emoji: '👋' + } + ] + + const initialStarterGroup = { + id: 1, + name: 'starter-posts', + slug: 'starter-posts', + avatar_url: 'https://d3ngex8q79bk55.cloudfront.net/misc/default_community_avatar.png', + banner_url: 'https://d3ngex8q79bk55.cloudfront.net/misc/default_community_banner.jpg', + group_data_type: 1, + visibility: 1, + accessibility: 1, + settings: { allow_group_invites: false, public_member_directory: false } + } + + const now = new Date().toISOString() + const initialWidgets = ` + INSERT INTO "public"."widgets"("id","name","created_at") VALUES + (1,E'text_block','${now}'), + (2,E'announcements','${now}'), + (3,E'active_members','${now}'), + (4,E'requests_offers','${now}'), + (5,E'posts','${now}'), + (6,E'community_topics','${now}'), + (7,E'events','${now}'), + (8,E'project_activity','${now}'), + (9,E'group_affiliations','${now}'), + (10,E'map','${now}');` + + const axolotlUser = { + email: 'edward+axolotl@hylo.com', + name: 'Hylo the Axolotl', + avatar_url: 'https://d3ngex8q79bk55.cloudfront.net/evo-uploads/user/13986/userAvatar/13986/Hylo%20the%20Axolotl%20Face.png', + active: true, + email_validated: true, + created_at: now, + bio: "Hi! I'm Hylo the Axolotl. I'm here to help you make your community a more connected, collaborative, and creative place.", + banner_url: 'https://d3ngex8q79bk55.cloudfront.net/misc/default_user_banner.jpg', + extra_info: '[www.hylo.com](http://www.hylo.com/)', + new_notification_count: 0, + settings: '{"locale": "en", "digest_frequency": "daily", "dm_notifications": "email", "post_notifications": "important", "comment_notifications": "email"}', + url: 'http://www.hylo.com/' + } + + const initialPost = { + name: 'Welcome to your community on Hylo! Here are a few tips.', + description: `

Hylo makes it easy for you to reach out to people in your community with special skills, connections and resources that can help you achieve your goals.

\ +

Here’s how to get the most out of Hylo:

+

Start off by making a post. Looking for help on something? Try creating a Request. Have a special skill or resource to share? Try making an Offer.

+

Know someone who might be able to help out on a Request? You can @tag other users in a community, or click on someone’s name to message them directly.

+

Need more help? Please check out our User Guide at engage.hylo.com or email us at hello@hylo.com 

+

Happy connecting,

+

<3 Hylo Helper

`, + type: 'offer', + created_at: now, + active: true, + visibility: 0, + user_id: 1 + } + + // now wipe and initialize the database + // NB: Deletes ALL existing users, groups, and posts, etc return knex('groups_posts').del() + .then(() => knex('group_memberships_common_roles').del()) + .then(() => knex('groups_tags').del()) + .then(() => knex('tag_follows').del()) + .then(() => knex('linked_account').del()) .then(() => knex('group_memberships').del()) - .then(() => knex('groups').del()) // Deletes ALL existing entries - .then(() => knex('groups') - .insert({ - id: 1, - name: 'starter-posts', - slug: 'starter-posts', - avatar_url: 'https://d3ngex8q79bk55.cloudfront.net/misc/default_community_avatar.png', - banner_url: 'https://d3ngex8q79bk55.cloudfront.net/misc/default_community_banner.jpg', - group_data_type: 1, - visibility: 1, - accessibility: 1, - settings: { allow_group_invites: false, public_member_directory: false } + .then(() => knex('group_widgets').del()) + .then(() => knex('posts').del()) + .then( async () => { + await knex('groups').del() + await knex.raw('ALTER SEQUENCE groups_id_seq RESTART WITH 1') + await knex('groups').insert(initialStarterGroup) + + await knex('responsibilities').del() + await knex.raw('ALTER SEQUENCE responsibilities_id_seq RESTART WITH 1') + await knex('responsibilities').insert(responsibilitiesData) + + await knex('common_roles').del() + await knex.raw('ALTER SEQUENCE common_roles_id_seq RESTART WITH 1') + await knex('common_roles').insert(commonRolesData) + + await knex('widgets').del() + await knex.raw('ALTER SEQUENCE widgets_id_seq RESTART WITH 1') + await knex.raw(initialWidgets) + + await knex('users').del() + await knex.raw('ALTER SEQUENCE users_seq RESTART WITH 1') + await knex('users').insert(axolotlUser) + + // await knex('posts').del() <== have to delete before deleting users + await knex.raw('ALTER SEQUENCE post_seq RESTART WITH 1') + await knex('posts').insert(initialPost) + + await knex('groups_posts').del() + await knex.raw('ALTER SEQUENCE post_community_id_seq RESTART WITH 1') + await knex('groups_posts').insert({ + post_id: 1, + group_id: 1 }) - ) + }) } From 17ec533312e72cdc313ee2eaa128eb15f8a5caa0 Mon Sep 17 00:00:00 2001 From: Kevin Triplett Date: Thu, 14 Nov 2024 13:41:53 -0600 Subject: [PATCH 2/4] update README re seeds --- apps/backend/README.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/backend/README.md b/apps/backend/README.md index 43486fd561..5186253e3e 100644 --- a/apps/backend/README.md +++ b/apps/backend/README.md @@ -81,7 +81,9 @@ UPLOADER_PATH_PREFIX=[ path ] ### populating the database -Make sure you have Postgres running with PostGIS installed and your user has create database privileges, then you should be able to: +Make sure you have Postgres running with PostGIS installed and your user has create database privileges. Then you should be able to use one of the following scenarios. + +#### creating a fresh instance without fake data ```shell createdb hylo -h localhost @@ -89,20 +91,39 @@ createdb hylo_test -h localhost cat migrations/schema.sql | psql hylo yarn knex seed:run ``` -This is only necessary if you're creating a fresh instance and aren't going to be loading a database snapshot (see below for that process). If you're new, you can also use the dummy seed to truncate everything and populate a bunch of fake data including a test account login like so: + +Note: *This will trash everything in your current `hylo` database, so make sure you really want to do that!* You can run `yarn knex seed:run` anytime you want to refresh the database *but this will delete groups, users, and posts.* + +#### creating a fresh instance with generic data ```shell +createdb hylo -h localhost +createdb hylo_test -h localhost +cat migrations/schema.sql | psql hylo NODE_ENV=dummy yarn knex seed:run ``` -*This will trash everything in your current `hylo` database, so make sure you really want to do that!* The script will ask for confirmation. By default the test user will be `test@hylo.com` with password `hylo`, configurable at the top of `seeds/dummy/dummy.js`. +The script will ask for confirmation. By default the test user will be `test@hylo.com` with password `hylo`, configurable at the top of `seeds/dummy/dummy.js`. + +Note: *This will trash everything in your current `hylo` database, so make sure you really want to do that!* You can run `NODE_ENV=dummy yarn knex seed:run` anytime you want to refresh the database *but this will delete groups, users, and posts.* + +#### creating a fresh instance with farm data If you are working with farm group data, run this command to add fake farm data to either a database copy, or a db copy generated by the seeding function. This function is *not* designed to be run more than once successfully. ```shell +createdb hylo -h localhost +createdb hylo_test -h localhost +cat migrations/schema.sql | psql hylo NODE_ENV=farmdev yarn knex seed:run ``` +Note: You will not be able to run `NODE_ENV=farmdev yarn knex seed:run` more than once. Alternatively, drop the production DBs and re-run the script. + +#### creating a fresh instance and loading database snapshot + +Scroll down to "loading database snapshots" 👇 + ### running the dev server ```shell From 7ae12ab34799f9ff450d2281af7722600c639cc8 Mon Sep 17 00:00:00 2001 From: Kevin Triplett Date: Thu, 14 Nov 2024 13:44:39 -0600 Subject: [PATCH 3/4] remove trailing backslash from seeds --- apps/backend/seeds/groups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/backend/seeds/groups.js b/apps/backend/seeds/groups.js index a5a765ad67..7eefa714fb 100644 --- a/apps/backend/seeds/groups.js +++ b/apps/backend/seeds/groups.js @@ -87,7 +87,7 @@ exports.seed = function (knex, Promise) { const initialPost = { name: 'Welcome to your community on Hylo! Here are a few tips.', - description: `

Hylo makes it easy for you to reach out to people in your community with special skills, connections and resources that can help you achieve your goals.

\ + description: `

Hylo makes it easy for you to reach out to people in your community with special skills, connections and resources that can help you achieve your goals.

Here’s how to get the most out of Hylo:

Start off by making a post. Looking for help on something? Try creating a Request. Have a special skill or resource to share? Try making an Offer.

Know someone who might be able to help out on a Request? You can @tag other users in a community, or click on someone’s name to message them directly.

From a1e8e40eab7e39a3a7c366c4eb89267fd3769662 Mon Sep 17 00:00:00 2001 From: Kevin Triplett Date: Thu, 14 Nov 2024 19:04:28 -0600 Subject: [PATCH 4/4] remove starterGroup id to fix seeds bug --- apps/backend/seeds/groups.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/backend/seeds/groups.js b/apps/backend/seeds/groups.js index 7eefa714fb..160fa533f1 100644 --- a/apps/backend/seeds/groups.js +++ b/apps/backend/seeds/groups.js @@ -45,7 +45,6 @@ exports.seed = function (knex, Promise) { ] const initialStarterGroup = { - id: 1, name: 'starter-posts', slug: 'starter-posts', avatar_url: 'https://d3ngex8q79bk55.cloudfront.net/misc/default_community_avatar.png',