ignis-db 0.2.0

A comprehensive PostgreSQL ORM with macro-driven schema management
Documentation
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
use crate::builders::traits::{
    ConditionalBuilder, InspectableBuilder, SchemaBuilder, ValidatableBuilder,
};
use crate::builders::validation::SequenceBuildError;
use crate::schema::Sequence;

/// Builder for constructing database sequences
#[derive(Debug, Clone)]
pub struct SequenceBuilder {
    name: Option<String>,
    schema: Option<String>,
    data_type: Option<String>,
    start_value: Option<i64>,
    minimum_value: Option<i64>,
    maximum_value: Option<i64>,
    increment: Option<i64>,
    cycle: Option<bool>,
    cache: Option<i64>,
    owner: Option<String>,
    comment: Option<String>,
}

impl SequenceBuilder {
    /// Create a new sequence builder
    pub fn new() -> Self {
        Self {
            name: None,
            schema: None,
            data_type: None,
            start_value: None,
            minimum_value: None,
            maximum_value: None,
            increment: None,
            cycle: None,
            cache: None,
            owner: None,
            comment: None,
        }
    }

    /// Set the sequence name
    pub fn name(mut self, name: impl Into<String>) -> Self {
        self.name = Some(name.into());
        self
    }

    /// Set the sequence name (mutable reference version for conditional building)
    pub fn set_name(&mut self, name: impl Into<String>) {
        self.name = Some(name.into());
    }

    /// Set the schema name
    pub fn in_schema(mut self, schema: impl Into<String>) -> Self {
        self.schema = Some(schema.into());
        self
    }

    /// Set the schema name (mutable reference version for conditional building)
    pub fn set_schema(&mut self, schema: impl Into<String>) {
        self.schema = Some(schema.into());
    }

    /// Set the data type
    pub fn data_type(mut self, data_type: impl Into<String>) -> Self {
        self.data_type = Some(data_type.into());
        self
    }

    /// Set the data type (mutable reference version for conditional building)
    pub fn set_data_type(&mut self, data_type: impl Into<String>) {
        self.data_type = Some(data_type.into());
    }

    /// Set the start value
    pub fn start_value(mut self, start: i64) -> Self {
        self.start_value = Some(start);
        self
    }

    /// Set the start value (mutable reference version for conditional building)
    pub fn set_start_value(&mut self, start: i64) {
        self.start_value = Some(start);
    }

    /// Set the minimum value
    pub fn minimum_value(mut self, min: i64) -> Self {
        self.minimum_value = Some(min);
        self
    }

    /// Set the minimum value (mutable reference version for conditional building)
    pub fn set_minimum_value(&mut self, min: i64) {
        self.minimum_value = Some(min);
    }

    /// Set the maximum value
    pub fn maximum_value(mut self, max: i64) -> Self {
        self.maximum_value = Some(max);
        self
    }

    /// Set the maximum value (mutable reference version for conditional building)
    pub fn set_maximum_value(&mut self, max: i64) {
        self.maximum_value = Some(max);
    }

    /// Set the increment
    pub fn increment(mut self, increment: i64) -> Self {
        self.increment = Some(increment);
        self
    }

    /// Set the increment (mutable reference version for conditional building)
    pub fn set_increment(&mut self, increment: i64) {
        self.increment = Some(increment);
    }

    /// Set the cycle behavior
    pub fn cycle(mut self, cycle: bool) -> Self {
        self.cycle = Some(cycle);
        self
    }

    /// Set the cycle behavior (mutable reference version for conditional building)
    pub fn set_cycle(&mut self, cycle: bool) {
        self.cycle = Some(cycle);
    }

    /// Set the cache size
    pub fn cache(mut self, cache: i64) -> Self {
        self.cache = Some(cache);
        self
    }

    /// Set the cache size (mutable reference version for conditional building)
    pub fn set_cache(&mut self, cache: i64) {
        self.cache = Some(cache);
    }

    /// Set the owner
    pub fn owner(mut self, owner: impl Into<String>) -> Self {
        self.owner = Some(owner.into());
        self
    }

    /// Set the owner (mutable reference version for conditional building)
    pub fn set_owner(&mut self, owner: impl Into<String>) {
        self.owner = Some(owner.into());
    }

    /// Set a comment on the sequence
    pub fn comment(mut self, comment: impl Into<String>) -> Self {
        self.comment = Some(comment.into());
        self
    }

    /// Set a comment on the sequence (mutable reference version for conditional building)
    pub fn set_comment(&mut self, comment: impl Into<String>) {
        self.comment = Some(comment.into());
    }

    // Convenience methods for specific sequence patterns
    /// Create a simple sequence
    pub fn simple() -> Self {
        Self::new()
    }

    /// Create an auto-increment sequence
    pub fn auto_increment() -> Self {
        Self::new()
            .data_type("BIGINT")
            .start_value(1)
            .increment(1)
            .minimum_value(1)
            .cycle(false)
    }

    /// Create a small auto-increment sequence
    pub fn small_auto_increment() -> Self {
        Self::new()
            .data_type("INTEGER")
            .start_value(1)
            .increment(1)
            .minimum_value(1)
            .cycle(false)
    }

    /// Create a large auto-increment sequence
    pub fn large_auto_increment() -> Self {
        Self::new()
            .data_type("BIGINT")
            .start_value(1)
            .increment(1)
            .minimum_value(1)
            .maximum_value(9223372036854775807)
            .cycle(false)
    }

    /// Create a timestamp sequence
    pub fn timestamp() -> Self {
        Self::new()
            .data_type("BIGINT")
            .start_value(0)
            .increment(1)
            .cycle(false)
    }

    /// Create a counter sequence
    pub fn counter() -> Self {
        Self::new()
            .data_type("INTEGER")
            .start_value(0)
            .increment(1)
            .minimum_value(0)
            .cycle(false)
    }

    /// Create a cycling sequence
    pub fn cycling() -> Self {
        Self::new()
            .data_type("INTEGER")
            .start_value(1)
            .increment(1)
            .minimum_value(1)
            .maximum_value(1000)
            .cycle(true)
    }

    /// Create a cached sequence
    pub fn cached() -> Self {
        Self::new()
            .data_type("BIGINT")
            .start_value(1)
            .increment(1)
            .cache(10)
    }

    // Inspection methods
    /// Get the sequence name
    #[inline]
    pub fn get_name(&self) -> Option<&str> {
        self.name.as_deref()
    }

    /// Get the schema name
    #[inline]
    pub fn get_schema(&self) -> Option<&str> {
        self.schema.as_deref()
    }

    /// Get the data type
    #[inline]
    pub fn get_data_type(&self) -> Option<&str> {
        self.data_type.as_deref()
    }

    /// Get the start value
    pub fn get_start_value(&self) -> Option<i64> {
        self.start_value
    }

    /// Get the minimum value
    pub fn get_minimum_value(&self) -> Option<i64> {
        self.minimum_value
    }

    /// Get the maximum value
    pub fn get_maximum_value(&self) -> Option<i64> {
        self.maximum_value
    }

    /// Get the increment
    pub fn get_increment(&self) -> Option<i64> {
        self.increment
    }

    /// Get the cycle behavior
    pub fn get_cycle(&self) -> Option<bool> {
        self.cycle
    }

    /// Get the cache size
    pub fn get_cache(&self) -> Option<i64> {
        self.cache
    }

    /// Get the owner
    pub fn get_owner(&self) -> Option<&str> {
        self.owner.as_deref()
    }

    /// Get the comment
    pub fn get_comment(&self) -> Option<&str> {
        self.comment.as_deref()
    }

    /// Check if the sequence has a name
    pub fn has_name(&self) -> bool {
        self.name.is_some()
    }

    /// Check if the sequence has a schema
    pub fn has_schema(&self) -> bool {
        self.schema.is_some()
    }

    /// Check if the sequence has a data type
    pub fn has_data_type(&self) -> bool {
        self.data_type.is_some()
    }

    /// Check if the sequence has a start value
    pub fn has_start_value(&self) -> bool {
        self.start_value.is_some()
    }

    /// Check if the sequence has a minimum value
    pub fn has_minimum_value(&self) -> bool {
        self.minimum_value.is_some()
    }

    /// Check if the sequence has a maximum value
    pub fn has_maximum_value(&self) -> bool {
        self.maximum_value.is_some()
    }

    /// Check if the sequence has an increment
    pub fn has_increment(&self) -> bool {
        self.increment.is_some()
    }

    /// Check if the sequence has cycle behavior set
    pub fn has_cycle(&self) -> bool {
        self.cycle.is_some()
    }

    /// Check if the sequence has a cache size
    pub fn has_cache(&self) -> bool {
        self.cache.is_some()
    }

    /// Check if the sequence has an owner
    pub fn has_owner(&self) -> bool {
        self.owner.is_some()
    }

    /// Check if the sequence has a comment
    pub fn has_comment(&self) -> bool {
        self.comment.is_some()
    }
}

impl SchemaBuilder for SequenceBuilder {
    type Output = Sequence;
    type Error = SequenceBuildError;

    fn build(self) -> Result<Self::Output, Self::Error> {
        // Validate the sequence before building
        if !self.is_valid() {
            let errors = self.validation_errors();
            return Err(SequenceBuildError::ValidationError(errors.join("; ")));
        }

        // Build the sequence
        let sequence = Sequence {
            name: self.name.unwrap_or_else(|| "sequence".to_string()),
            schema: self.schema,
            data_type: self.data_type.unwrap_or_else(|| "BIGINT".to_string()),
            start_value: self.start_value,
            minimum_value: self.minimum_value,
            maximum_value: self.maximum_value,
            increment: self.increment,
            cycle: self.cycle,
            cache: self.cache,
            owner: self.owner,
            comment: self.comment,
        };

        Ok(sequence)
    }
}

impl ValidatableBuilder for SequenceBuilder {
    fn is_valid(&self) -> bool {
        self.validation_errors().is_empty()
    }

    fn validation_errors(&self) -> Vec<String> {
        let mut errors = Vec::new();

        // Validate that a name is specified
        if self.name.is_none() {
            errors.push("Sequence must have a name".to_string());
        }

        // Validate sequence name if provided
        if let Some(ref name) = self.name {
            if name.trim().is_empty() {
                errors.push("Sequence name cannot be empty".to_string());
            }
        }

        // Validate schema name if provided
        if let Some(ref schema) = self.schema {
            if schema.trim().is_empty() {
                errors.push("Schema name cannot be empty".to_string());
            }
        }

        // Validate data type if provided
        if let Some(ref data_type) = self.data_type {
            if data_type.trim().is_empty() {
                errors.push("Data type cannot be empty".to_string());
            }
        }

        // Validate owner if provided
        if let Some(ref owner) = self.owner {
            if owner.trim().is_empty() {
                errors.push("Owner cannot be empty".to_string());
            }
        }

        // Validate comment if provided
        if let Some(ref comment) = self.comment {
            if comment.trim().is_empty() {
                errors.push("Comment cannot be empty".to_string());
            }
        }

        // Validate numeric constraints
        if let (Some(min), Some(max)) = (self.minimum_value, self.maximum_value) {
            if min >= max {
                errors.push("Minimum value must be less than maximum value".to_string());
            }
        }

        if let Some(increment) = self.increment {
            if increment == 0 {
                errors.push("Increment cannot be zero".to_string());
            }
        }

        if let Some(cache) = self.cache {
            if cache <= 0 {
                errors.push("Cache size must be positive".to_string());
            }
        }

        errors
    }
}

impl ConditionalBuilder for SequenceBuilder {
    fn when<F>(mut self, condition: bool, config_fn: F) -> Self
    where
        F: FnOnce(&mut Self),
        Self: Sized,
    {
        if condition {
            config_fn(&mut self);
        }
        self
    }
}

impl InspectableBuilder for SequenceBuilder {
    fn debug_info(&self) -> String {
        format!(
            "SequenceBuilder {{ name: {:?}, schema: {:?}, data_type: {:?}, start_value: {:?}, increment: {:?}, cycle: {:?} }}",
            self.name, self.schema, self.data_type, self.start_value, self.increment, self.cycle
        )
    }

    fn summary(&self) -> String {
        let mut parts = Vec::new();

        parts.push("Sequence".to_string());

        // Name and schema
        if let Some(ref name) = self.name {
            if let Some(ref schema) = self.schema {
                parts.push(format!("{}.{}", schema, name));
            } else {
                parts.push(format!("'{}'", name));
            }
        }

        // Data type
        if let Some(ref data_type) = self.data_type {
            parts.push(format!("type: {}", data_type));
        }

        // Start value
        if let Some(start) = self.start_value {
            parts.push(format!("starts at {}", start));
        }

        // Increment
        if let Some(increment) = self.increment {
            parts.push(format!("increments by {}", increment));
        }

        // Range
        let mut range_parts = Vec::new();
        if let Some(min) = self.minimum_value {
            range_parts.push(format!("min: {}", min));
        }
        if let Some(max) = self.maximum_value {
            range_parts.push(format!("max: {}", max));
        }
        if !range_parts.is_empty() {
            parts.push(format!("range: {}", range_parts.join(", ")));
        }

        // Cycle behavior
        if let Some(cycle) = self.cycle {
            if cycle {
                parts.push("cycles".to_string());
            } else {
                parts.push("no cycle".to_string());
            }
        }

        // Cache
        if let Some(cache) = self.cache {
            parts.push(format!("cache: {}", cache));
        }

        // Owner
        if let Some(ref owner) = self.owner {
            parts.push(format!("owned by {}", owner));
        }

        // Comment
        if let Some(ref comment) = self.comment {
            parts.push(format!("with comment: {}", comment));
        }

        parts.join(", ")
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_basic_sequence() {
        let sequence = SequenceBuilder::new()
            .name("user_id_seq")
            .data_type("BIGINT")
            .start_value(1)
            .increment(1)
            .build()
            .unwrap();

        assert_eq!(sequence.name, "user_id_seq");
        assert_eq!(sequence.data_type, "BIGINT");
        assert_eq!(sequence.start_value, Some(1));
        assert_eq!(sequence.increment, Some(1));
    }

    #[test]
    fn test_sequence_with_schema() {
        let sequence = SequenceBuilder::new()
            .name("order_id_seq")
            .in_schema("public")
            .data_type("INTEGER")
            .start_value(1000)
            .increment(10)
            .build()
            .unwrap();

        assert_eq!(sequence.name, "order_id_seq");
        assert_eq!(sequence.schema, Some("public".to_string()));
        assert_eq!(sequence.data_type, "INTEGER");
        assert_eq!(sequence.start_value, Some(1000));
        assert_eq!(sequence.increment, Some(10));
    }

    #[test]
    fn test_convenience_methods() {
        let auto_seq = SequenceBuilder::auto_increment()
            .name("auto_seq")
            .build()
            .unwrap();

        let small_seq = SequenceBuilder::small_auto_increment()
            .name("small_seq")
            .build()
            .unwrap();

        let large_seq = SequenceBuilder::large_auto_increment()
            .name("large_seq")
            .build()
            .unwrap();

        let timestamp_seq = SequenceBuilder::timestamp()
            .name("timestamp_seq")
            .build()
            .unwrap();

        let counter_seq = SequenceBuilder::counter()
            .name("counter_seq")
            .build()
            .unwrap();

        let cycling_seq = SequenceBuilder::cycling()
            .name("cycling_seq")
            .build()
            .unwrap();

        let cached_seq = SequenceBuilder::cached()
            .name("cached_seq")
            .build()
            .unwrap();

        assert_eq!(auto_seq.data_type, "BIGINT");
        assert_eq!(auto_seq.start_value, Some(1));
        assert_eq!(auto_seq.increment, Some(1));
        assert_eq!(auto_seq.minimum_value, Some(1));
        assert_eq!(auto_seq.cycle, Some(false));

        assert_eq!(small_seq.data_type, "INTEGER");
        assert_eq!(small_seq.start_value, Some(1));

        assert_eq!(large_seq.data_type, "BIGINT");
        assert_eq!(large_seq.maximum_value, Some(9223372036854775807));

        assert_eq!(timestamp_seq.data_type, "BIGINT");
        assert_eq!(timestamp_seq.start_value, Some(0));

        assert_eq!(counter_seq.data_type, "INTEGER");
        assert_eq!(counter_seq.start_value, Some(0));
        assert_eq!(counter_seq.minimum_value, Some(0));

        assert_eq!(cycling_seq.data_type, "INTEGER");
        assert_eq!(cycling_seq.maximum_value, Some(1000));
        assert_eq!(cycling_seq.cycle, Some(true));

        assert_eq!(cached_seq.data_type, "BIGINT");
        assert_eq!(cached_seq.cache, Some(10));
    }

    #[test]
    fn test_sequence_with_all_properties() {
        let sequence = SequenceBuilder::new()
            .name("comprehensive_seq")
            .in_schema("public")
            .data_type("BIGINT")
            .start_value(100)
            .minimum_value(1)
            .maximum_value(10000)
            .increment(5)
            .cycle(true)
            .cache(20)
            .owner("postgres")
            .comment("Comprehensive test sequence")
            .build()
            .unwrap();

        assert_eq!(sequence.name, "comprehensive_seq");
        assert_eq!(sequence.schema, Some("public".to_string()));
        assert_eq!(sequence.data_type, "BIGINT");
        assert_eq!(sequence.start_value, Some(100));
        assert_eq!(sequence.minimum_value, Some(1));
        assert_eq!(sequence.maximum_value, Some(10000));
        assert_eq!(sequence.increment, Some(5));
        assert_eq!(sequence.cycle, Some(true));
        assert_eq!(sequence.cache, Some(20));
        assert_eq!(sequence.owner, Some("postgres".to_string()));
        assert_eq!(
            sequence.comment,
            Some("Comprehensive test sequence".to_string())
        );
    }

    #[test]
    fn test_validation_errors() {
        // No name
        let result = SequenceBuilder::new().data_type("BIGINT").build();
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            SequenceBuildError::ValidationError(_)
        ));

        // Empty name
        let result = SequenceBuilder::new().name("").data_type("BIGINT").build();
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            SequenceBuildError::ValidationError(_)
        ));

        // Invalid range (min >= max)
        let result = SequenceBuilder::new()
            .name("test_seq")
            .data_type("INTEGER")
            .minimum_value(100)
            .maximum_value(50)
            .build();
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            SequenceBuildError::ValidationError(_)
        ));

        // Zero increment
        let result = SequenceBuilder::new()
            .name("test_seq")
            .data_type("INTEGER")
            .increment(0)
            .build();
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            SequenceBuildError::ValidationError(_)
        ));

        // Negative cache
        let result = SequenceBuilder::new()
            .name("test_seq")
            .data_type("INTEGER")
            .cache(-5)
            .build();
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            SequenceBuildError::ValidationError(_)
        ));
    }

    #[test]
    fn test_conditional_builder() {
        let condition = true;
        let sequence = SequenceBuilder::new()
            .when(condition, |s| {
                s.set_name("sequence_when_true");
                s.set_data_type("INTEGER");
                s.set_start_value(100);
                s.set_increment(5);
            })
            .build()
            .unwrap();

        assert_eq!(sequence.name, "sequence_when_true");
        assert_eq!(sequence.data_type, "INTEGER");
        assert_eq!(sequence.start_value, Some(100));
        assert_eq!(sequence.increment, Some(5));
    }

    #[test]
    fn test_inspection_methods() {
        let builder = SequenceBuilder::new()
            .name("test_sequence")
            .in_schema("public")
            .data_type("BIGINT")
            .start_value(1)
            .minimum_value(1)
            .maximum_value(1000)
            .increment(1)
            .cycle(false)
            .cache(10)
            .owner("postgres")
            .comment("This is a test sequence");

        assert_eq!(builder.get_name(), Some("test_sequence"));
        assert_eq!(builder.get_schema(), Some("public"));
        assert_eq!(builder.get_data_type(), Some("BIGINT"));
        assert_eq!(builder.get_start_value(), Some(1));
        assert_eq!(builder.get_minimum_value(), Some(1));
        assert_eq!(builder.get_maximum_value(), Some(1000));
        assert_eq!(builder.get_increment(), Some(1));
        assert_eq!(builder.get_cycle(), Some(false));
        assert_eq!(builder.get_cache(), Some(10));
        assert_eq!(builder.get_owner(), Some("postgres"));
        assert_eq!(builder.get_comment(), Some("This is a test sequence"));

        assert!(builder.has_name());
        assert!(builder.has_schema());
        assert!(builder.has_data_type());
        assert!(builder.has_start_value());
        assert!(builder.has_minimum_value());
        assert!(builder.has_maximum_value());
        assert!(builder.has_increment());
        assert!(builder.has_cycle());
        assert!(builder.has_cache());
        assert!(builder.has_owner());
        assert!(builder.has_comment());
    }

    #[test]
    fn test_debug_info_and_summary() {
        let builder = SequenceBuilder::new()
            .name("user_id_seq")
            .in_schema("public")
            .data_type("BIGINT")
            .start_value(1)
            .increment(1)
            .minimum_value(1)
            .maximum_value(1000000)
            .cycle(false)
            .cache(10)
            .comment("User ID sequence");

        let debug_info = builder.debug_info();
        let summary = builder.summary();

        assert!(debug_info.contains("SequenceBuilder"));
        assert!(debug_info.contains("user_id_seq"));
        assert!(debug_info.contains("public"));

        assert!(summary.contains("Sequence"));
        assert!(summary.contains("public.user_id_seq"));
        assert!(summary.contains("type: BIGINT"));
        assert!(summary.contains("starts at 1"));
        assert!(summary.contains("increments by 1"));
        assert!(summary.contains("range: min: 1, max: 1000000"));
        assert!(summary.contains("no cycle"));
        assert!(summary.contains("cache: 10"));
        assert!(summary.contains("with comment: User ID sequence"));
    }

    #[test]
    fn test_sequence_with_complex_constraints() {
        let sequence = SequenceBuilder::new()
            .name("complex_seq")
            .data_type("INTEGER")
            .start_value(-1000)
            .minimum_value(-10000)
            .maximum_value(10000)
            .increment(100)
            .cycle(true)
            .cache(50)
            .build()
            .unwrap();

        assert_eq!(sequence.name, "complex_seq");
        assert_eq!(sequence.data_type, "INTEGER");
        assert_eq!(sequence.start_value, Some(-1000));
        assert_eq!(sequence.minimum_value, Some(-10000));
        assert_eq!(sequence.maximum_value, Some(10000));
        assert_eq!(sequence.increment, Some(100));
        assert_eq!(sequence.cycle, Some(true));
        assert_eq!(sequence.cache, Some(50));
    }

    #[test]
    fn test_sequence_with_owner() {
        let sequence = SequenceBuilder::new()
            .name("owned_seq")
            .data_type("BIGINT")
            .owner("app_user")
            .build()
            .unwrap();

        assert_eq!(sequence.name, "owned_seq");
        assert_eq!(sequence.owner, Some("app_user".to_string()));
    }

    #[test]
    fn test_sequence_with_comment() {
        let sequence = SequenceBuilder::new()
            .name("commented_seq")
            .data_type("INTEGER")
            .comment("This sequence is used for generating unique IDs")
            .build()
            .unwrap();

        assert_eq!(sequence.name, "commented_seq");
        assert_eq!(
            sequence.comment,
            Some("This sequence is used for generating unique IDs".to_string())
        );
    }
}