Skip to content

Commit 5d06459

Browse files
committed
AI sahit
1 parent 3b1319f commit 5d06459

13 files changed

Lines changed: 379 additions & 251 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use diesel::SqliteConnection;
2+
3+
use miden_node_db::DatabaseError;
4+
5+
pub(super) const SQL: &str = include_str!("up.sql");
6+
7+
pub(super) fn data_migration(_conn: &mut SqliteConnection) -> Result<(), DatabaseError> {
8+
Ok(())
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use diesel::SqliteConnection;
2+
3+
use crate::DatabaseError;
4+
5+
pub(super) const SQL: &str = include_str!("up.sql");
6+
7+
pub(super) fn data_migration(_conn: &mut SqliteConnection) -> Result<(), DatabaseError> {
8+
Ok(())
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use diesel::SqliteConnection;
2+
3+
use crate::DatabaseError;
4+
5+
pub(super) const SQL: &str = include_str!("up.sql");
6+
7+
pub(super) fn data_migration(_conn: &mut SqliteConnection) -> Result<(), DatabaseError> {
8+
Ok(())
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use diesel::SqliteConnection;
2+
3+
use crate::DatabaseError;
4+
5+
pub(super) const SQL: &str = include_str!("up.sql");
6+
7+
pub(super) fn data_migration(_conn: &mut SqliteConnection) -> Result<(), DatabaseError> {
8+
Ok(())
9+
}

crates/store/src/db/migrations/20260223160000_add_block_header_commitment/mod.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
//! Data migration
2-
//!
3-
//! Populate the new column `commitment` in table `block_headers` from the existing serialized
4-
//! representation.
5-
6-
use diesel::migration::MigrationVersion;
71
use diesel::sqlite::SqliteConnection;
82
use diesel::{QueryableByName, RunQueryDsl};
93
use miden_protocol::block::BlockHeader;
104
use miden_protocol::utils::{Deserializable, Serializable};
115

126
use crate::DatabaseError;
137

8+
pub(super) const SQL: &str = include_str!("up.sql");
9+
1410
#[derive(QueryableByName)]
1511
struct BlockHeaderRow {
1612
#[diesel(sql_type = diesel::sql_types::BigInt)]
@@ -19,18 +15,12 @@ struct BlockHeaderRow {
1915
block_header: Vec<u8>,
2016
}
2117

22-
pub(super) fn run(
23-
conn: &mut SqliteConnection,
24-
version: &MigrationVersion<'_>,
25-
) -> std::result::Result<(), DatabaseError> {
26-
backfill_block_header_commitments(conn, version)
18+
pub(super) fn data_migration(conn: &mut SqliteConnection) -> Result<(), DatabaseError> {
19+
backfill_block_header_commitments(conn)
2720
}
2821

2922
/// Backfill block header commitments for existing rows in table `block_headers`
30-
pub(super) fn backfill_block_header_commitments(
31-
conn: &mut SqliteConnection,
32-
_version: &MigrationVersion<'_>,
33-
) -> std::result::Result<(), DatabaseError> {
23+
fn backfill_block_header_commitments(conn: &mut SqliteConnection) -> Result<(), DatabaseError> {
3424
let block_headers = diesel::sql_query(
3525
"SELECT block_num, block_header FROM block_headers WHERE commitment IS NULL",
3626
)
Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,15 @@
1-
//! Data migration declaration and representation utilities
2-
31
use diesel::SqliteConnection;
4-
use diesel::migration::MigrationVersion;
52

63
use crate::DatabaseError;
74

8-
/// A data migration to apply post schema migration.
9-
pub(crate) struct DataMigration {
10-
/// Identifier of the migration which matches the directory name containing the up.sql/down.sql
11-
/// files
5+
pub(crate) struct Migration {
126
pub(crate) id: &'static str,
13-
/// Closure to execute given a connection
14-
pub(crate) run: fn(
15-
&mut SqliteConnection,
16-
&MigrationVersion<'static>,
17-
) -> std::result::Result<(), DatabaseError>,
7+
pub(crate) sql: &'static str,
8+
pub(crate) data_migration: fn(&mut SqliteConnection) -> Result<(), DatabaseError>,
189
}
1910

20-
impl std::fmt::Debug for DataMigration {
11+
impl std::fmt::Debug for Migration {
2112
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2213
std::fmt::Debug::fmt(self.id, f)
2314
}
2415
}
25-
26-
// Helper macro to resolve an optional explicit run identifier or default to `<name>::run`.
27-
#[macro_export]
28-
macro_rules! __data_migrations_resolve_run {
29-
($name:ident, $run:ident) => {
30-
$name::$run
31-
};
32-
($name:ident) => {
33-
$name::run
34-
};
35-
}
36-
37-
#[macro_export]
38-
macro_rules! __data_migrations_mod {
39-
($module:ident, $path:literal) => {
40-
// It'd be great if we could use `$(concat!($path, "/mod.rs"))`
41-
// but it's already required at module traversal, so it _must be_
42-
// a true literal string `"somewhere/mod.rs"`.
43-
#[path = $path]
44-
mod $module;
45-
};
46-
}
47-
48-
/// Helper macro to both declare the `fn run` (default), declare the module, and keeps it in a slice
49-
/// for later usage
50-
///
51-
/// Example:
52-
///
53-
/// ```ignore
54-
/// post_migrations! {
55-
/// const DATA_MIGRATION_CODE: &[DataMigration] = {
56-
/// "20260223160000_add_block_header_commitment/mod.rs" => alt_name_add_commitment,
57-
/// "20260223160001_bar/mod.rs" => bar::fun,
58-
/// };
59-
/// }
60-
/// ```
61-
///
62-
/// expands to
63-
///
64-
///```ignore
65-
/// mod alt_name_add_commitment { include!{ "20260223160000_add_block_header_commitment/mod.rs" } }
66-
/// mod bar { include!{ "20260223160001_bar/mod.rs" } }
67-
///
68-
/// const DATA_MIGRATION_CODE: &[DataMigration] = {
69-
/// PostMigration { id: "20260223160000_add_block_header_commitment", add_block_header::run },
70-
/// PostMigration { id: "20260223160001_bar", bar::fun },
71-
/// };
72-
/// ```
73-
#[macro_export]
74-
macro_rules! data_migrations {
75-
(const $binding:ident : &[$what:ty] = {$($path:literal => $module:ident $(:: $run:ident)?),* $(,)?};) => {
76-
$(
77-
$crate::__data_migrations_mod!{$module, $path}
78-
)*
79-
static $binding: ::std::sync::LazyLock<Box<[$what]>> =
80-
::std::sync::LazyLock::new(|| {
81-
Box::new([
82-
$(
83-
$crate::db::migrations::data::DataMigration {
84-
id: $path.split_once('/').expect("Has one path segment at least").0,
85-
run: $crate::__data_migrations_resolve_run!($module $(, $run)?),
86-
},
87-
)*
88-
])
89-
});
90-
};
91-
}

0 commit comments

Comments
 (0)