transact/state/merkle/sql/migration/sqlite/mod.rs
1/*
2 * Copyright 2021 Cargill Incorporated
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * -----------------------------------------------------------------------------
16 */
17
18//! Defines methods and utilities to interact with merkle-radix tables in a SQLite database.
19
20embed_migrations!("./src/state/merkle/sql/migration/sqlite/migrations");
21
22use crate::error::InternalError;
23use crate::state::merkle::sql::backend::{Connection, SqliteBackend, WriteExclusiveExecute};
24
25use super::MigrationManager;
26
27/// Run database migrations to create tables defined for the SqlMerkleState.
28///
29/// # Arguments
30///
31/// * `conn` - Connection to SQLite database
32///
33pub fn run_migrations(conn: &diesel::sqlite::SqliteConnection) -> Result<(), InternalError> {
34 embedded_migrations::run(conn).map_err(|err| InternalError::from_source(Box::new(err)))?;
35
36 debug!("Successfully applied Transact SQLite migrations");
37
38 Ok(())
39}
40
41impl MigrationManager for SqliteBackend {
42 fn run_migrations(&self) -> Result<(), InternalError> {
43 self.execute_write(|conn| run_migrations(conn.as_inner()))
44 }
45}