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 seed-from-repo script for database population #749

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

harishv7
Copy link
Contributor

@harishv7 harishv7 commented Oct 9, 2024

Problem

Closes #[insert issue number]

Solution

This PR introduces a new script to seed the database from a repository structure. It includes a template for environment variables and a TypeScript script to process and insert data into the database.

Breaking Changes

  • No - this PR is backwards compatible

Features:

  • Added a new script to seed the database from a repository structure
  • Implemented functionality to process directories and files recursively
  • Created functions to insert blobs, resources, and versions into the database

Improvements:

  • Included performance profiling to measure the execution time of the seeding process

Tests

The following tests should be run to confirm functionality:

  1. Run the script with a sample repository structure and verify that the database is correctly seeded
  2. Test with different directory structures to ensure proper handling of nested folders and files
  3. Verify that the script correctly handles various file types (JSON files for pages, directories for folders)
  4. Check that the performance profiling accurately reports the execution time

New scripts:

  • seed-from-repo : Seeds the database with content from a repository structure

New dependencies:

  • dotenv : For loading environment variables
  • pg : PostgreSQL client for database operations

New dev dependencies:

  • @types/pg : TypeScript types for the PostgreSQL client

Copy link

vercel bot commented Oct 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
isomer-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 8:18am

Copy link
Contributor Author

harishv7 commented Oct 9, 2024

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

Join @harishv7 and the rest of your teammates on Graphite Graphite

@harishv7 harishv7 changed the title add script to migrate from gh repo Add seed-from-repo script for database population Oct 9, 2024
@harishv7 harishv7 marked this pull request as ready for review October 9, 2024 09:14
@harishv7 harishv7 requested a review from a team as a code owner October 9, 2024 09:14
@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Oct 9, 2024

Datadog Report

Branch report: 10-09-add_script_to_migrate_from_gh_repo
Commit report: 34c96c7
Test service: isomer-studio

✅ 0 Failed, 129 Passed, 23 Skipped, 33.29s 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.

can i understand, what issue is this trying to solve?

@@ -0,0 +1,3 @@
DATABASE_URL=postgresql://root:root@localhost/isomer_studio
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency purposes with .env.example, should we use postgres://root:root@localhost:5432/app?

Copy link
Contributor Author

@adriangohjw While we were building studio, sites that were to be migrated we crafted as github repos. Now we need a way to migrate these repos into DB

} finally {
await client.end()
const end = performance.now() // End profiling
console.log(`Database seeding completed in ${(end - start) / 1000} seconds`)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - wondering if DATABASE_URL is invalid and client.connect() fails, will this console.log statement be a false positive?

return result.rows.length > 0
}

async function seedDatabase(client: Client) {
Copy link
Contributor

Choose a reason for hiding this comment

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

im assuming not checking and creating Collection is intentional?

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 we also use ResourceType.Page etc. instead of hardcoding for single source of truth?

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