@@ -3,11 +3,29 @@ namespace Migration;
33/// <summary>
44/// Fluent builder for schema definitions.
55/// </summary>
6+ /// <example>
7+ /// <code>
8+ /// var schema = SchemaFactory.Define("MyDatabase")
9+ /// .Table("users", t => t
10+ /// .Column("id", PortableTypes.Uuid, c => c.PrimaryKey())
11+ /// .Column("email", PortableTypes.VarChar(255), c => c.NotNull())
12+ /// .Column("created_at", PortableTypes.DateTime, c => c.DefaultLql("now()"))
13+ /// .Index("idx_users_email", "email", unique: true))
14+ /// .Table("orders", t => t
15+ /// .Column("id", PortableTypes.Int, c => c.Identity().PrimaryKey())
16+ /// .Column("user_id", PortableTypes.Uuid, c => c.NotNull())
17+ /// .Column("total", PortableTypes.Decimal(10, 2))
18+ /// .ForeignKey("user_id", "users", "id", onDelete: ForeignKeyAction.Cascade))
19+ /// .Build();
20+ /// </code>
21+ /// </example>
622public static class SchemaFactory
723{
824 /// <summary>
925 /// Start defining a schema with the given name.
1026 /// </summary>
27+ /// <param name="name">The name of the schema/database.</param>
28+ /// <returns>A <see cref="SchemaBuilder"/> for fluent configuration.</returns>
1129 public static SchemaBuilder Define ( string name ) => new ( name ) ;
1230}
1331
@@ -28,8 +46,20 @@ public static class Schema
2846}
2947
3048/// <summary>
31- /// Builder for creating schema definitions.
49+ /// Builder for creating schema definitions with tables, columns, indexes, and constraints .
3250/// </summary>
51+ /// <example>
52+ /// <code>
53+ /// var schema = Schema.Define("inventory")
54+ /// .Table("products", t => t
55+ /// .Column("id", PortableTypes.Int, c => c.Identity().PrimaryKey())
56+ /// .Column("name", PortableTypes.VarChar(100), c => c.NotNull())
57+ /// .Column("price", PortableTypes.Decimal(10, 2), c => c.NotNull().Check("price >= 0"))
58+ /// .Column("sku", PortableTypes.VarChar(50), c => c.NotNull())
59+ /// .Unique("uq_products_sku", "sku"))
60+ /// .Build();
61+ /// </code>
62+ /// </example>
3363public sealed class SchemaBuilder
3464{
3565 private readonly string _name ;
@@ -66,8 +96,23 @@ public SchemaBuilder Table(string schema, string name, Action<TableBuilder> conf
6696}
6797
6898/// <summary>
69- /// Builder for creating table definitions.
99+ /// Builder for creating table definitions with columns, indexes, foreign keys, and constraints .
70100/// </summary>
101+ /// <example>
102+ /// <code>
103+ /// // Define a table with various column types and constraints
104+ /// .Table("employees", t => t
105+ /// .Column("id", PortableTypes.Uuid, c => c.PrimaryKey().DefaultLql("gen_uuid()"))
106+ /// .Column("name", PortableTypes.VarChar(100), c => c.NotNull())
107+ /// .Column("email", PortableTypes.VarChar(255), c => c.NotNull())
108+ /// .Column("department_id", PortableTypes.Int)
109+ /// .Column("salary", PortableTypes.Decimal(12, 2))
110+ /// .Column("hired_at", PortableTypes.DateTime, c => c.DefaultLql("now()"))
111+ /// .Index("idx_employees_email", "email", unique: true)
112+ /// .Index("idx_employees_dept", "department_id")
113+ /// .ForeignKey("department_id", "departments", "id"))
114+ /// </code>
115+ /// </example>
71116public sealed class TableBuilder
72117{
73118 private readonly string _name ;
@@ -279,8 +324,26 @@ internal TableDefinition Build() =>
279324}
280325
281326/// <summary>
282- /// Builder for creating column definitions.
327+ /// Builder for creating column definitions with type, nullability, defaults, and constraints .
283328/// </summary>
329+ /// <example>
330+ /// <code>
331+ /// // UUID primary key with auto-generation
332+ /// .Column("id", PortableTypes.Uuid, c => c.PrimaryKey().DefaultLql("gen_uuid()"))
333+ ///
334+ /// // Required string with max length
335+ /// .Column("name", PortableTypes.VarChar(100), c => c.NotNull())
336+ ///
337+ /// // Auto-increment integer
338+ /// .Column("sequence", PortableTypes.Int, c => c.Identity())
339+ ///
340+ /// // Decimal with precision and check constraint
341+ /// .Column("price", PortableTypes.Decimal(10, 2), c => c.NotNull().Check("price > 0"))
342+ ///
343+ /// // DateTime with default to current timestamp
344+ /// .Column("created_at", PortableTypes.DateTime, c => c.DefaultLql("now()"))
345+ /// </code>
346+ /// </example>
284347public sealed class ColumnBuilder
285348{
286349 private readonly string _name ;
0 commit comments