v002-create-products.vala 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using InvercargillSql;
  2. using InvercargillSql.Migrations;
  3. /**
  4. * Migration to create the products table with category index.
  5. */
  6. public class V002_CreateProducts : Migration {
  7. public override string migration_namespace { get { return "app"; } }
  8. public override uint64 serial { get { return 2; } }
  9. public override string name { get { return "CreateProducts"; } }
  10. public override void up(MigrationBuilder b) throws SqlError {
  11. b.create_table("products", t => {
  12. t.column<int64?>("id")
  13. .primary_key()
  14. .auto_increment();
  15. t.column<string>("name")
  16. .not_null();
  17. t.column<string>("category")
  18. .not_null();
  19. t.column<double?>("price");
  20. t.column<int64?>("stock");
  21. // Create index on category for fast category-based queries
  22. t.index("idx_products_category").on_column("category");
  23. });
  24. }
  25. public override void down(MigrationBuilder b) throws SqlError {
  26. b.drop_table("products");
  27. }
  28. }