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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! # Database Schema Introspection and Code Generation
//!
//! This module provides functionality to generate Reinhardt ORM models from existing
//! database schemas. It follows the Database-First approach similar to sqlboiler/ent.
//!
//! ## Features
//!
//! - **Schema Reading**: Uses `DatabaseIntrospector` to read existing database schemas
//! - **Type Mapping**: Maps SQL types to Rust types with proper nullable handling
//! - **Code Generation**: Generates `#[model(...)]` annotated Rust structs
//! - **Relationship Detection**: Automatically detects FK relationships
//! - **Configuration**: TOML-based configuration for customization
//!
//! ## Usage
//!
//! ```bash
//! cargo run --bin manage introspect -d postgres://localhost/mydb -o src/models/
//! ```
//!
//! ## Configuration
//!
//! Create `reinhardt-introspect.toml`:
//!
//! ```toml
//! [database]
//! url = "postgres://user:pass@localhost:5432/myapp"
//!
//! [output]
//! directory = "src/models/generated"
//!
//! [generation]
//! app_label = "myapp"
//! detect_relationships = true
//!
//! [tables]
//! include = [".*"]
//! exclude = ["^pg_", "^reinhardt_migrations"]
//!
//! [type_overrides]
//! "users.status" = "UserStatus"
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
use DatabaseSchema;
use ;
/// Introspect a database and generate Rust model code.
///
/// This is the main entry point for the introspection feature.
///
/// # Arguments
///
/// * `config` - Configuration for introspection
/// * `introspector` - Database introspector implementation
///
/// # Returns
///
/// Generated output containing model files
///
/// # Example
///
/// ```rust,ignore
/// use reinhardt_db::migrations::introspect::{IntrospectConfig, introspect};
/// use reinhardt_db::migrations::introspection::PostgresIntrospector;
///
/// let config = IntrospectConfig::from_file("reinhardt-introspect.toml")?;
/// let introspector = PostgresIntrospector::new(pool);
/// let schema = introspector.read_schema().await?;
/// let output = generate_models(&config, &schema)?;
/// ```
/// Write generated files to disk.
///
/// # Arguments
///
/// * `output` - Generated output from `generate_models`
/// * `force` - Overwrite existing files
///
/// # Errors
///
/// Returns error if files already exist and `force` is false
/// Preview generated code without writing to disk.
///
/// Useful for `--dry-run` mode.