1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct Format {
13 pub id: &'static str,
16 pub version: &'static str,
18}
19
20pub const POSTGRES_SCHEMA: i32 = 14;
23
24const fn digits(n: i64) -> &'static str {
26 match n {
27 1 => "1",
28 2 => "2",
29 3 => "3",
30 4 => "4",
31 5 => "5",
32 6 => "6",
33 7 => "7",
34 8 => "8",
35 9 => "9",
36 10 => "10",
37 11 => "11",
38 12 => "12",
39 13 => "13",
40 14 => "14",
41 15 => "15",
42 16 => "16",
43 _ => panic!("add the number to formats::digits"),
44 }
45}
46
47pub const FORMATS: &[Format] = &[
49 Format {
50 id: "catalog",
51 version: digits(crate::catalog::SCHEMA_VERSION),
52 },
53 Format {
54 id: "postgres",
55 version: digits(POSTGRES_SCHEMA as i64),
56 },
57 Format {
58 id: "envelope",
59 version: digits(crate::envelope::FORMAT as i64),
60 },
61 Format {
62 id: "parquet-storage",
63 version: crate::store::manifest::FORMAT,
64 },
65 Format {
66 id: "export-manifest",
67 version: digits(crate::export::MANIFEST_FORMAT as i64),
68 },
69 Format {
70 id: "export-columns",
71 version: crate::export::columns::SCHEMA,
72 },
73];
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 fn version(id: &str) -> &'static str {
80 FORMATS
81 .iter()
82 .find(|f| f.id == id)
83 .unwrap_or_else(|| panic!("{id} is listed"))
84 .version
85 }
86
87 #[test]
88 fn each_version_is_its_formats_own_constant() {
89 assert_eq!(
90 version("catalog"),
91 crate::catalog::SCHEMA_VERSION.to_string(),
92 "catalog"
93 );
94 assert_eq!(
95 version("envelope"),
96 crate::envelope::FORMAT.to_string(),
97 "envelope"
98 );
99 assert_eq!(
100 version("parquet-storage"),
101 crate::store::manifest::FORMAT,
102 "parquet"
103 );
104 assert_eq!(
105 version("export-manifest"),
106 crate::export::MANIFEST_FORMAT.to_string(),
107 "export manifest"
108 );
109 assert_eq!(
110 version("export-columns"),
111 crate::export::columns::SCHEMA,
112 "export columns"
113 );
114 assert_eq!(version("postgres"), POSTGRES_SCHEMA.to_string(), "postgres");
115 }
116
117 #[test]
118 fn digits_writes_each_number_it_knows() {
119 for n in 1..=16 {
120 assert_eq!(digits(n), n.to_string(), "{n}");
121 }
122 }
123
124 #[test]
125 #[should_panic(expected = "add the number")]
126 fn digits_refuses_a_number_it_does_not_know() {
127 let _ = digits(17);
128 }
129}