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

UN-101: Migrate database to Turso and Libsql #115

Merged
merged 10 commits into from
Aug 30, 2024

Conversation

damiensedgwick
Copy link
Contributor

@damiensedgwick damiensedgwick commented Aug 23, 2024

Migration from Vercel/PostgreSQL to Turso/LibSQL

Overview

This PR implements a significant infrastructure change, moving our database from Vercel's PostgreSQL to Turso's LibSQL. This migration offers several advantages:

  1. Increased storage capacity
  2. Elimination of bandwidth restrictions
  3. Potential for improved performance and scalability

Implementation Details

  • Followed the Turso documentation for integration with Drizzle ORM
  • Updated database configuration and connection logic
  • Modified queries and schema definitions to ensure SQLite compatibility

Configuration Notes

  • Current database configuration points to .env.local
  • For production deployment, this should be updated to use .env

Database Ownership

  • The Turso database is currently set up under a personal account
  • Action Item: Establish a team account or organization-level ownership for the database

Next Steps

  1. Review and test all database interactions to ensure full compatibility
  2. Update deployment scripts and environment variables for production
  3. Set up a team account on Turso and migrate the database ownership
  4. Update documentation to reflect the new database setup and any changed procedures

Additional Considerations

  • Verify backup and restore procedures for the new database
  • Assess any impacts on application performance and optimize if necessary
  • Consider implementing database migration scripts for smooth transitions in the future

Please review these changes carefully, particularly focusing on SQLite-specific adaptations and any performance implications.

Copy link

linear bot commented Aug 23, 2024

Copy link

vercel bot commented Aug 23, 2024

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

Name Status Preview Comments Updated (UTC)
atproto-browser ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 30, 2024 8:53pm
frontpage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 30, 2024 8:53pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unravel ⬜️ Ignored (Inspect) Visit Preview Aug 30, 2024 8:53pm

@damiensedgwick
Copy link
Contributor Author

Most of the grunt work has been done. schema.ts has been migrated to sqlite syntax. For some of the properties, there was not a direct migration such as serial for postgres, this is just an integer and there is no timestamp / date column for drizzle + sqlite so this is just a text field.

New migrations were generated and pushed to turso with no issues but there is still work to do where there is now some type incompatibilities.

tursoooo

@damiensedgwick
Copy link
Contributor Author

transaction files have been migrated to sqlite syntax also now, pr needs to be tested at this point, posts created / selected etc, same for comments. I am unable to login to the app at the moment so I cannot test this myself.

@damiensedgwick
Copy link
Contributor Author

Bigint does not exist in sqlite but I noticed this was used for the consumed offsets, sqlite integers have a max value of 263 - 1 == 9223372036854775807 so I figure this should be fine.

@damiensedgwick
Copy link
Contributor Author

Fix this: frontpage:build: Type error: Type 'string' is not assignable to type 'Date'.

packages/frontpage/lib/data/db/post.ts Show resolved Hide resolved
packages/frontpage/lib/data/db/post.ts Outdated Show resolved Hide resolved
packages/frontpage/lib/db.ts Outdated Show resolved Hide resolved
packages/frontpage/lib/schema.ts Outdated Show resolved Hide resolved
packages/frontpage/lib/schema.ts Outdated Show resolved Hide resolved
@damiensedgwick damiensedgwick marked this pull request as ready for review August 30, 2024 15:38
tom-sherman
tom-sherman previously approved these changes Aug 30, 2024
@damiensedgwick damiensedgwick merged commit 6eae90a into main Aug 30, 2024
5 checks passed
@damiensedgwick damiensedgwick deleted the damien/un-101/move-over-to-turso branch August 30, 2024 20:57
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