1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! A stable checksum over a migration's rendered DDL.
//!
//! Applying a migration records a checksum of the SQL it renders. On a later run
//! the checksum is recomputed and compared, so an already-applied migration whose
//! definition changed can be detected. The hash is computed over the rendered SQL
//! (the semantic artifact), not the source file.
//!
//! FNV-1a is used: a small, stable, dependency-free hash. This is change
//! detection, not tamper resistance, so a non-cryptographic hash is appropriate.
/// FNV-1a 64-bit offset basis.
const OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;
/// FNV-1a 64-bit prime.
const PRIME: u64 = 0x0000_0100_0000_01b3;
/// Computes the FNV-1a 64-bit hash of `bytes`.
/// Returns a stable hex checksum of the rendered statements.
///
/// # Examples
///
/// ```
/// use tork_orm_core::migration::checksum::checksum_of;
///
/// let a = checksum_of(&["CREATE TABLE x (id INTEGER)".to_string()]);
/// let b = checksum_of(&["CREATE TABLE x (id INTEGER)".to_string()]);
/// assert_eq!(a, b);
/// assert_eq!(a.len(), 16);
/// ```