Schema Management
Tether automates the management of your local SQLite database schema by mirroring the Postgres schema from your Supabase project. This includes handling migrations, creating tables, and managing relationships.
As SQLite is a full SQL database, you have to manage migrations of the local schema over time when you change the schema in your Supabase project so that you can persist the existing data in running installations of your application.
Tether will configure and manage these for you.
Schema Generation
When you run the generator, Tether will:
- Fetch the schema from your Supabase project.
- Create files in
/lib/database/schemathat represent the schema. The system will compare these over time to create migrations. - Generate the necessary SQLite commands to create the tables and relationships in your local SQLite database.
- Create a
supabase_schema.dartfile that is a snapshot of the current schema. This file is used by the managers to interact with relationships. - Create migrations for the local SQLite database in
lib/database/sqlite_migrations. - Create the database files for the local SQLite database. Typically at
lib/database/database.dart.
Schema Conventions
Tether will try to following:
- Use the same table names as in your Supabase project. i.e.
user_profilesin Supabase will beuser_profilesin SQLite. - Use the same column names as in your Supabase project. i.e.
some_columnin Supabase will besome_columnin SQLite. - Use the same data types as in your Supabase project or will transform them to the closest equivalent in SQLite. Most data types will be mapped to the corred Dart type by the Models system.
- Use the same relationships as in your Supabase project. i.e. a
profilestable with a foreign key to auserstable will create a relationship in the SQLite database. - Use the same indexes as in your Supabase project. i.e. a
profilestable with an index on theemailcolumn will create an index in the SQLite database.
Tether does not currently provide a way to manually define things like indexes on the local DB outside of the automatic generation.
Best Practices
- Tether will automatically rename column that are reserved words in Dart. For
example, a column named
defaultin Supabase will be renamed todefaultValuein SQLite.