Synchronizing Your Database


Denogres features bi-directional synchronization that is designed to ensure that your database schema and your project Models in full alignment, maintaining a single, consistent source of truth. In this section we will cover two key functionalities: database introspection (--db-pull) and extrospection (--db-sync).


Before using DenoGres in a project please ensure that you initialize your project with the following CLI command:


denogres --init

In your project's root directory, you should now see a .env file for your database connection URI, a models folder where your model.ts file will be generated, and a migrations/log folder which will contain a historical reference to prior pull/sync requests.


After running the init command, update the .env file to contain your database's connection URI.


DATABASE_URI=driver://user:password@host:port/database_name


Database Introspection --db-pull


Upon the initial configuration (project initialization, setting up the database URI) Database introspection will automatically generate TypeScript Models of your database tables into a models/model.ts file. Note that any subsequent changes to the model.ts file will require an additional sync to ensure the database schema is updated to reflect accordingly (see the following section.)

To introspect and generate the associated models within the model.ts file, execute the the following CLI command:


denogres --db-pull


Database Synchronization --db-sync


While database introspection (via --db-pull) provides users the capability to generate Models in alignment with a database schema, there are potentially instances where users may create additional Models and would like to ensure that the database is updated accordingly to maintain synchronicity between the two. In addition to --db-pull, Denogres also includes --db-sync functionality that will revise the PostgreSQL schema based on the DenoGres model.ts file.

Once completed changes to your model have been made, execute the following CLI command:


denogres --db-sync