Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collection management scripts for MOH TOSP #955

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

harishv7
Copy link
Contributor

@harishv7 harishv7 commented Dec 23, 2024

Problem

Needed scripts to manage collection resources in the database for content migration.

Closes ISOM-1700

Solution

Breaking Changes

  • No - this PR is backwards compatible

Features:

  • Added script to backup collections and their resources to JSON files
  • Added script to create new collections from local JSON files
  • Added script to safely delete collections and their associated resources
  • Added script to publish draft collections and their child resources

New scripts:

  • backupCollectionById.ts: Backs up a collection and its resources to JSON files
  • createCollectionFromLocal.ts: Creates a new collection from local JSON content
  • deleteCollectionById.ts: Safely deletes a collection and all associated resources
  • publishDraftCollection.ts: Publishes a draft collection and its child resources

Tests

Scripts should be tested with:

  1. Backup of an existing collection
  2. Creation of a new collection from backed up files
  3. Publishing the newly created collection
  4. Deletion of test collections

Each script includes error handling and transaction support to maintain data integrity.

@harishv7 harishv7 changed the title tosp migration scripts Add collection management scripts for MOH TOSP Dec 23, 2024
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@harishv7 harishv7 marked this pull request as ready for review December 23, 2024 03:54
@harishv7 harishv7 requested a review from a team as a code owner December 23, 2024 03:54
Copy link

linear bot commented Dec 23, 2024

@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Dec 23, 2024

Datadog Report

Branch report: 12-23-tosp_migration_scripts
Commit report: e9e6f32
Test service: isomer-studio

✅ 0 Failed, 245 Passed, 36 Skipped, 47.51s Total Time
➡️ Test Sessions change in coverage: 1 no change

Copy link
Contributor

@adriangohjw adriangohjw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this will only be used once a year:

  • (nit) Use Generated Enums: Let's consider using generatedEnums (like ResourceType.Collection) instead of hardcoded strings. This will help keep the file updated with future changes, especially since it lacks tests.
  • (nit) Keyword Arguments: Since many functions have multiple parameters, using keyword arguments over positional arguments might enhance clarity and safety.
  • Add a README: Could you please add a simple README outlining the expected folder structure and usage steps? This will be helpful since this script is run infrequently.

Thank you!

import { FileLogger } from "../FileLogger"

// Update the logger path if required
const logger = new FileLogger("./publishCollectionById.log")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - should be publishDraftCollection.log for consistency across files

export const createCollectionFromLocal = async (
contentDir: string,
siteId: number,
indexPageName: string, // should be placed outside the folder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if i understand why this should be placed outside the folder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants