| | | 1 | | namespace Elsa.Persistence.VNext.Builders; |
| | | 2 | | |
| | 34 | 3 | | public class PersistenceSchemaBuilder(string name) |
| | | 4 | | { |
| | 34 | 5 | | private readonly List<PersistenceTable> _tables = []; |
| | 34 | 6 | | private readonly List<PersistenceStorageUnit> _storageUnits = []; |
| | 34 | 7 | | private int _version = 1; |
| | | 8 | | |
| | | 9 | | public PersistenceSchemaBuilder Version(int version) |
| | | 10 | | { |
| | 13 | 11 | | if (version < 1) |
| | 0 | 12 | | throw new ArgumentOutOfRangeException(nameof(version), version, "Schema version must be greater than zero.") |
| | | 13 | | |
| | 13 | 14 | | _version = version; |
| | 13 | 15 | | return this; |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | public PersistenceSchemaBuilder Table(string name, Action<PersistenceTableBuilder> configure, string? schema = null) |
| | | 19 | | { |
| | 0 | 20 | | var builder = new PersistenceTableBuilder(name, schema); |
| | 0 | 21 | | configure(builder); |
| | 0 | 22 | | _tables.Add(builder.Build()); |
| | 0 | 23 | | return this; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | public PersistenceSchemaBuilder StorageUnit(string name, Action<PersistenceStorageUnitBuilder> configure, string? @n |
| | | 27 | | { |
| | 42 | 28 | | var builder = new PersistenceStorageUnitBuilder(name, @namespace); |
| | 42 | 29 | | configure(builder); |
| | 42 | 30 | | _storageUnits.Add(builder.Build()); |
| | 42 | 31 | | return this; |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | public PersistenceSchema Build() |
| | | 35 | | { |
| | 34 | 36 | | return new PersistenceSchema(Name: name, Version: _version, Tables: _tables.ToList(), StorageUnits: _storageUnit |
| | | 37 | | } |
| | | 38 | | } |