v002-create-products.vala 1014 B

12345678910111213141516171819202122232425262728293031
  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 int version { get { return 2; } }
  8. public override string name { get { return "CreateProducts"; } }
  9. public override void up(MigrationBuilder b) throws SqlError {
  10. b.create_table("products", t => {
  11. t.column<int64?>("id")
  12. .primary_key()
  13. .auto_increment();
  14. t.column<string>("name")
  15. .not_null();
  16. t.column<string>("category")
  17. .not_null();
  18. t.column<double?>("price");
  19. t.column<int64?>("stock");
  20. // Create index on category for fast category-based queries
  21. t.index("idx_products_category").on_column("category");
  22. });
  23. }
  24. public override void down(MigrationBuilder b) throws SqlError {
  25. b.drop_table("products");
  26. }
  27. }