pub trait SchemaConnector: Send + Sync + 'static {
Show 29 methods // Required methods fn set_host(&mut self, host: Arc<dyn ConnectorHost>); fn set_params(&mut self, params: ConnectorParams) -> ConnectorResult<()>; fn set_preview_features( &mut self, preview_features: BitFlags<PreviewFeature> ); fn acquire_lock(&mut self) -> BoxFuture<'_, ConnectorResult<()>>; fn apply_migration<'a>( &'a mut self, migration: &'a Migration ) -> BoxFuture<'a, ConnectorResult<u32>>; fn apply_script<'a>( &'a mut self, migration_name: &'a str, script: &'a str ) -> BoxFuture<'a, ConnectorResult<()>>; fn connector_type(&self) -> &'static str; fn connection_string(&self) -> Option<&str>; fn create_database(&mut self) -> BoxFuture<'_, ConnectorResult<String>>; fn db_execute( &mut self, script: String ) -> BoxFuture<'_, ConnectorResult<()>>; fn diff(&self, from: DatabaseSchema, to: DatabaseSchema) -> Migration; fn drop_database(&mut self) -> BoxFuture<'_, ConnectorResult<()>>; fn empty_database_schema(&self) -> DatabaseSchema; fn ensure_connection_validity( &mut self ) -> BoxFuture<'_, ConnectorResult<()>>; fn host(&self) -> &Arc<dyn ConnectorHost>; fn version(&mut self) -> BoxFuture<'_, ConnectorResult<String>>; fn render_script( &self, migration: &Migration, diagnostics: &DestructiveChangeDiagnostics ) -> ConnectorResult<String>; fn reset( &mut self, soft: bool, namespaces: Option<Namespaces> ) -> BoxFuture<'_, ConnectorResult<()>>; fn migration_file_extension(&self) -> &'static str; fn migration_len(&self, migration: &Migration) -> usize; fn migration_persistence(&mut self) -> &mut dyn MigrationPersistence; fn migration_summary(&self, migration: &Migration) -> String; fn destructive_change_checker( &mut self ) -> &mut dyn DestructiveChangeChecker; fn database_schema_from_diff_target<'a>( &'a mut self, target: DiffTarget<'a>, shadow_database_connection_string: Option<String>, namespaces: Option<Namespaces> ) -> BoxFuture<'a, ConnectorResult<DatabaseSchema>>; fn introspect<'a>( &'a mut self, ctx: &'a IntrospectionContext ) -> BoxFuture<'a, ConnectorResult<IntrospectionResult>>; fn validate_migrations<'a>( &'a mut self, _migrations: &'a [MigrationDirectory], namespaces: Option<Namespaces> ) -> BoxFuture<'a, ConnectorResult<()>>; fn extract_namespaces(&self, schema: &DatabaseSchema) -> Option<Namespaces>; // Provided methods fn check_database_version_compatibility( &self, _datamodel: &ValidatedSchema ) -> Option<DatabaseVersionIncompatibility> { ... } fn migration_is_empty(&self, migration: &Migration) -> bool { ... }
}
Expand description

The top-level trait for connectors. This is the abstraction the schema engine core relies on to interface with different database backends.

Required Methods§

source

fn set_host(&mut self, host: Arc<dyn ConnectorHost>)

Accept a new ConnectorHost.

source

fn set_params(&mut self, params: ConnectorParams) -> ConnectorResult<()>

Accept and validate new ConnectorParams. This should fail if it is called twice on the same connector.

source

fn set_preview_features(&mut self, preview_features: BitFlags<PreviewFeature>)

Accept a new set of enabled preview features.

source

fn acquire_lock(&mut self) -> BoxFuture<'_, ConnectorResult<()>>

If possible on the target connector, acquire an advisory lock, so multiple instances of migrate do not run concurrently.

source

fn apply_migration<'a>( &'a mut self, migration: &'a Migration ) -> BoxFuture<'a, ConnectorResult<u32>>

Applies the migration to the database. Returns the number of executed steps.

source

fn apply_script<'a>( &'a mut self, migration_name: &'a str, script: &'a str ) -> BoxFuture<'a, ConnectorResult<()>>

Apply a migration script to the database. The migration persistence is managed by the core.

source

fn connector_type(&self) -> &'static str

A string that should identify what database backend is being used. Note that this is not necessarily the connector name. The SQL connector for example can return “postgresql”, “mysql” or “sqlite”.

source

fn connection_string(&self) -> Option<&str>

Return the connection string that was used to initialize this connector in set_params().

source

fn create_database(&mut self) -> BoxFuture<'_, ConnectorResult<String>>

Create the database referenced by Prisma schema that was used to initialize the connector.

source

fn db_execute(&mut self, script: String) -> BoxFuture<'_, ConnectorResult<()>>

Send a command to the database directly.

source

fn diff(&self, from: DatabaseSchema, to: DatabaseSchema) -> Migration

Create a migration by comparing two database schemas.

source

fn drop_database(&mut self) -> BoxFuture<'_, ConnectorResult<()>>

Drop the database referenced by Prisma schema that was used to initialize the connector.

source

fn empty_database_schema(&self) -> DatabaseSchema

An empty database schema (for diffing).

source

fn ensure_connection_validity(&mut self) -> BoxFuture<'_, ConnectorResult<()>>

Make sure the connection to the database is established and valid. Connectors can choose to connect lazily, but this method should force them to connect.

source

fn host(&self) -> &Arc<dyn ConnectorHost>

Return the ConnectorHost passed with set_host.

source

fn version(&mut self) -> BoxFuture<'_, ConnectorResult<String>>

The version of the underlying database.

source

fn render_script( &self, migration: &Migration, diagnostics: &DestructiveChangeDiagnostics ) -> ConnectorResult<String>

Render the migration to a runnable script.

This should always return with Ok in normal circumstances. The result is currently only used to signal when the connector does not support rendering to a script.

source

fn reset( &mut self, soft: bool, namespaces: Option<Namespaces> ) -> BoxFuture<'_, ConnectorResult<()>>

Drop all database state.

Set the soft parameter to true to force a soft-reset, that is to say a reset that does not drop the database.

source

fn migration_file_extension(&self) -> &'static str

The file extension for generated migration files.

source

fn migration_len(&self, migration: &Migration) -> usize

Return the number of steps in the migration. Invariant: migration_is_empty() == true iff migration_len() == 0.

source

fn migration_persistence(&mut self) -> &mut dyn MigrationPersistence

source

fn migration_summary(&self, migration: &Migration) -> String

Render a human-readable drift summary for the migration.

source

fn destructive_change_checker(&mut self) -> &mut dyn DestructiveChangeChecker

source

fn database_schema_from_diff_target<'a>( &'a mut self, target: DiffTarget<'a>, shadow_database_connection_string: Option<String>, namespaces: Option<Namespaces> ) -> BoxFuture<'a, ConnectorResult<DatabaseSchema>>

Read a schema for diffing. The shadow database connection string is strictly optional, you don’t need to pass it if a shadow database url was passed in params, or if it can be inferred from context, or if it isn’t necessary for the task at hand. When MultiSchema is enabled, the namespaces are required for diffing anything other than a prisma schema, because that information is otherwise unavailable.

source

fn introspect<'a>( &'a mut self, ctx: &'a IntrospectionContext ) -> BoxFuture<'a, ConnectorResult<IntrospectionResult>>

In-tro-spec-shon.

source

fn validate_migrations<'a>( &'a mut self, _migrations: &'a [MigrationDirectory], namespaces: Option<Namespaces> ) -> BoxFuture<'a, ConnectorResult<()>>

If possible, check that the passed in migrations apply cleanly.

source

fn extract_namespaces(&self, schema: &DatabaseSchema) -> Option<Namespaces>

Extract the namespaces from a Sql database schema (it will return None for mongodb).

Provided Methods§

source

fn check_database_version_compatibility( &self, _datamodel: &ValidatedSchema ) -> Option<DatabaseVersionIncompatibility>

Optionally check that the features implied by the provided datamodel are all compatible with the specific database version being used.

source

fn migration_is_empty(&self, migration: &Migration) -> bool

Return whether the migration is empty.

Implementors§