Trait schema_connector::SchemaConnector
source · 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§
sourcefn set_host(&mut self, host: Arc<dyn ConnectorHost>)
fn set_host(&mut self, host: Arc<dyn ConnectorHost>)
Accept a new ConnectorHost.
sourcefn set_params(&mut self, params: ConnectorParams) -> ConnectorResult<()>
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.
sourcefn set_preview_features(&mut self, preview_features: BitFlags<PreviewFeature>)
fn set_preview_features(&mut self, preview_features: BitFlags<PreviewFeature>)
Accept a new set of enabled preview features.
sourcefn acquire_lock(&mut self) -> BoxFuture<'_, ConnectorResult<()>>
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.
sourcefn apply_migration<'a>(
&'a mut self,
migration: &'a Migration
) -> BoxFuture<'a, ConnectorResult<u32>>
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.
sourcefn apply_script<'a>(
&'a mut self,
migration_name: &'a str,
script: &'a str
) -> BoxFuture<'a, ConnectorResult<()>>
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.
sourcefn connector_type(&self) -> &'static str
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”.
sourcefn connection_string(&self) -> Option<&str>
fn connection_string(&self) -> Option<&str>
Return the connection string that was used to initialize this connector in set_params().
sourcefn create_database(&mut self) -> BoxFuture<'_, ConnectorResult<String>>
fn create_database(&mut self) -> BoxFuture<'_, ConnectorResult<String>>
Create the database referenced by Prisma schema that was used to initialize the connector.
sourcefn db_execute(&mut self, script: String) -> BoxFuture<'_, ConnectorResult<()>>
fn db_execute(&mut self, script: String) -> BoxFuture<'_, ConnectorResult<()>>
Send a command to the database directly.
sourcefn diff(&self, from: DatabaseSchema, to: DatabaseSchema) -> Migration
fn diff(&self, from: DatabaseSchema, to: DatabaseSchema) -> Migration
Create a migration by comparing two database schemas.
sourcefn drop_database(&mut self) -> BoxFuture<'_, ConnectorResult<()>>
fn drop_database(&mut self) -> BoxFuture<'_, ConnectorResult<()>>
Drop the database referenced by Prisma schema that was used to initialize the connector.
sourcefn empty_database_schema(&self) -> DatabaseSchema
fn empty_database_schema(&self) -> DatabaseSchema
An empty database schema (for diffing).
sourcefn ensure_connection_validity(&mut self) -> BoxFuture<'_, ConnectorResult<()>>
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.
sourcefn host(&self) -> &Arc<dyn ConnectorHost>
fn host(&self) -> &Arc<dyn ConnectorHost>
Return the ConnectorHost passed with set_host.
sourcefn version(&mut self) -> BoxFuture<'_, ConnectorResult<String>>
fn version(&mut self) -> BoxFuture<'_, ConnectorResult<String>>
The version of the underlying database.
sourcefn render_script(
&self,
migration: &Migration,
diagnostics: &DestructiveChangeDiagnostics
) -> ConnectorResult<String>
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.
sourcefn reset(
&mut self,
soft: bool,
namespaces: Option<Namespaces>
) -> BoxFuture<'_, ConnectorResult<()>>
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.
sourcefn migration_file_extension(&self) -> &'static str
fn migration_file_extension(&self) -> &'static str
The file extension for generated migration files.
sourcefn migration_len(&self, migration: &Migration) -> usize
fn migration_len(&self, migration: &Migration) -> usize
Return the number of steps in the migration. Invariant: migration_is_empty() == true iff migration_len() == 0.
sourcefn migration_persistence(&mut self) -> &mut dyn MigrationPersistence
fn migration_persistence(&mut self) -> &mut dyn MigrationPersistence
See MigrationPersistence.
sourcefn migration_summary(&self, migration: &Migration) -> String
fn migration_summary(&self, migration: &Migration) -> String
Render a human-readable drift summary for the migration.
sourcefn destructive_change_checker(&mut self) -> &mut dyn DestructiveChangeChecker
fn destructive_change_checker(&mut self) -> &mut dyn DestructiveChangeChecker
sourcefn 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 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.
sourcefn introspect<'a>(
&'a mut self,
ctx: &'a IntrospectionContext
) -> BoxFuture<'a, ConnectorResult<IntrospectionResult>>
fn introspect<'a>( &'a mut self, ctx: &'a IntrospectionContext ) -> BoxFuture<'a, ConnectorResult<IntrospectionResult>>
In-tro-spec-shon.
sourcefn validate_migrations<'a>(
&'a mut self,
_migrations: &'a [MigrationDirectory],
namespaces: Option<Namespaces>
) -> BoxFuture<'a, ConnectorResult<()>>
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.
sourcefn extract_namespaces(&self, schema: &DatabaseSchema) -> Option<Namespaces>
fn extract_namespaces(&self, schema: &DatabaseSchema) -> Option<Namespaces>
Extract the namespaces from a Sql database schema (it will return None for mongodb).
Provided Methods§
sourcefn check_database_version_compatibility(
&self,
_datamodel: &ValidatedSchema
) -> Option<DatabaseVersionIncompatibility>
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.
sourcefn migration_is_empty(&self, migration: &Migration) -> bool
fn migration_is_empty(&self, migration: &Migration) -> bool
Return whether the migration is empty.