ApiLogicServer 14.2.20__py3-none-any.whl → 14.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/METADATA +2 -2
  2. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/RECORD +65 -47
  3. api_logic_server_cli/api_logic_server.py +4 -1
  4. api_logic_server_cli/api_logic_server_info.yaml +3 -3
  5. api_logic_server_cli/create_from_model/__pycache__/api_logic_server_utils.cpython-312.pyc +0 -0
  6. api_logic_server_cli/create_from_model/__pycache__/ont_build.cpython-312.pyc +0 -0
  7. api_logic_server_cli/create_from_model/__pycache__/ont_create.cpython-312.pyc +0 -0
  8. api_logic_server_cli/create_from_model/api_logic_server_utils.py +4 -0
  9. api_logic_server_cli/create_from_model/ont_build.py +53 -19
  10. api_logic_server_cli/create_from_model/ont_create.py +14 -5
  11. api_logic_server_cli/fragments/declare_logic.py +72 -0
  12. api_logic_server_cli/{prototypes/manager/system/genai/create_db_models_inserts/logic_discovery_prefix.py → fragments/declare_logic_begin.py} +2 -1
  13. api_logic_server_cli/fragments/declare_logic_end.py +52 -0
  14. api_logic_server_cli/genai/genai.py +21 -8
  15. api_logic_server_cli/genai/genai_logic_builder.py +14 -11
  16. api_logic_server_cli/genai/genai_svcs.py +102 -7
  17. api_logic_server_cli/model_migrator/model_migrator_start.py +1 -1
  18. api_logic_server_cli/model_migrator/reposreader.py +9 -1
  19. api_logic_server_cli/model_migrator/rule_obj.py +24 -6
  20. api_logic_server_cli/prototypes/base/api/api_discovery/ontimize_api.py +4 -1
  21. api_logic_server_cli/prototypes/base/config/activate_logicbank.py +8 -4
  22. api_logic_server_cli/prototypes/base/database/bind_dbs.py +1 -1
  23. api_logic_server_cli/prototypes/base/database/test_data/readme.md +5 -5
  24. api_logic_server_cli/prototypes/base/logic/declare_logic.py +8 -3
  25. api_logic_server_cli/prototypes/base/logic/load_verify_rules.py +216 -0
  26. api_logic_server_cli/prototypes/base/logic/logic_discovery/auto_discovery.py +22 -13
  27. api_logic_server_cli/prototypes/genai_demo/logic/declare_logic.py +29 -21
  28. api_logic_server_cli/prototypes/manager/README.md +18 -3
  29. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.response_example +19 -18
  30. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/.DS_Store +0 -0
  31. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/000_you_are.prompt +1 -0
  32. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/001_logic_training.prompt +314 -0
  33. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/002_create_db_models.prompt +150 -0
  34. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/003_create_db_models.response +134 -0
  35. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/004_iteratio_logic.prompt +131 -0
  36. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/005_create_db_models.response-example +141 -0
  37. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/create_db_models.py +105 -0
  38. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/db.dbml +70 -0
  39. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/readme.md +6 -0
  40. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/response.json +178 -0
  41. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/base_genai_demo_no_logic/logic/declare_logic.py +0 -1
  42. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  43. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/genai/examples/genai_demo/wg_dev_merge/base_genai_demo_no_logic/logic/declare_logic.py +0 -1
  44. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  45. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/genai/examples/genai_demo/wg_dev_merge/wg_genai_demo_no_logic_fixed_from_CLI/logic/declare_logic.py +0 -1
  46. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  47. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/system/genai/examples/genai_demo/wg_dev_merge/base_genai_demo_no_logic/logic/declare_logic.py +0 -1
  48. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/system/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  49. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/system/genai/examples/genai_demo/wg_dev_merge/wg_genai_demo_no_logic_fixed_from_CLI/logic/declare_logic.py +0 -1
  50. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/002_create_db_models.prompt +194 -0
  51. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/003_create_db_models.response +298 -0
  52. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/db.sqlite +0 -0
  53. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/readme.md +8 -0
  54. api_logic_server_cli/prototypes/manager/system/genai/learning_requests/logic_bank_api.prompt +14 -10
  55. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/iteration.prompt +2 -1
  56. api_logic_server_cli/prototypes/nw_no_cust/venv_setup/system_note.txt +1 -1
  57. api_logic_server_cli/prototypes/ont_app/templates/home_tree_template.html +9 -0
  58. api_logic_server_cli/prototypes/ont_app/templates/tree_routing.jinja +32 -0
  59. api_logic_server_cli/sqlacodegen_wrapper/sqlacodegen/sqlacodegen/__pycache__/codegen.cpython-312.pyc +0 -0
  60. api_logic_server_cli/sqlacodegen_wrapper/sqlacodegen/sqlacodegen/codegen.py +2 -1
  61. api_logic_server_cli/tools/mini_skel/logic/load_verify_rules.py +1 -1
  62. api_logic_server_cli/model_migrator/system/custom_endpoint.py +0 -545
  63. api_logic_server_cli/prototypes/base/database/test_data/z_test_data_rows.py +0 -98
  64. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/LICENSE +0 -0
  65. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/WHEEL +0 -0
  66. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/entry_points.txt +0 -0
  67. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,134 @@
1
+ {
2
+ "models": [
3
+ {
4
+ "classname": "Customer",
5
+ "code": "class Customer(Base):\n __tablename__ = 'customer'\n\n id = Column(Integer, primary_key=True)\n name = Column(String, unique=True)\n credit_limit = Column(Integer)\n balance = Column(Integer)\n ",
6
+ "description": "Model for customers, ensuring unique names and supporting logic for balance computation.",
7
+ "name": "Customer"
8
+ },
9
+ {
10
+ "classname": "Order",
11
+ "code": "class Order(Base):\n __tablename__ = 'order'\n\n id = Column(Integer, primary_key=True)\n customer_id = Column(Integer, ForeignKey('customer.id'), nullable=False)\n date_shipped = Column(DateTime)\n amount_total = Column(Integer)\n notes = Column(String)\n ",
12
+ "description": "Model for orders, with a reference to customers, a notes field, and computed total amount for logic enforcement.",
13
+ "name": "Order"
14
+ },
15
+ {
16
+ "classname": "Product",
17
+ "code": "class Product(Base):\n __tablename__ = 'product'\n\n id = Column(Integer, primary_key=True)\n unit_price = Column(Integer)\n \n ",
18
+ "description": "Model for products, storing unit prices to be copied to items.",
19
+ "name": "Product"
20
+ },
21
+ {
22
+ "classname": "Item",
23
+ "code": "class Item(Base):\n __tablename__ = 'item'\n\n id = Column(Integer, primary_key=True)\n order_id = Column(Integer, ForeignKey('order.id'))\n product_id = Column(Integer, ForeignKey('product.id'))\n quantity = Column(Integer, nullable=False)\n unit_price = Column(Integer)\n amount = Column(Integer)\n ",
24
+ "description": "Model for items, referencing orders and products, using unit_price copied from products and calculated amount.",
25
+ "name": "Item"
26
+ }
27
+ ],
28
+ "rules": [
29
+ {
30
+ "name": "Customer Balance Constraint",
31
+ "description": "Ensures that a Customer's balance does not exceed its credit limit.",
32
+ "use_case": "Check Credit",
33
+ "entity": "Customer",
34
+ "code": "Rule.constraint(validate=Customer,\n as_condition=lambda row: row.balance <= row.credit_limit,\n error_msg=\"Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})\")"
35
+ },
36
+ {
37
+ "name": "Customer Balance Computation",
38
+ "description": "Calculates Customer's balance as sum of Order amounts where date_shipped is null.",
39
+ "use_case": "Check Credit",
40
+ "entity": "Customer",
41
+ "code": "Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total, \n where=lambda row: row.date_shipped is None)"
42
+ },
43
+ {
44
+ "name": "Order Amount Total",
45
+ "description": "Calculates Order amount_total as sum of Item amounts.",
46
+ "use_case": "Check Credit",
47
+ "entity": "Order",
48
+ "code": "Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)"
49
+ },
50
+ {
51
+ "name": "Item Amount Calculation",
52
+ "description": "Calculates Item's amount as the product of quantity and unit_price.",
53
+ "use_case": "Check Credit",
54
+ "entity": "Item",
55
+ "code": "Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)"
56
+ },
57
+ {
58
+ "name": "Item Unit Price Copy",
59
+ "description": "Copies Product's unit_price to item's unit_price.",
60
+ "use_case": "Check Credit",
61
+ "entity": "Item",
62
+ "code": "Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)"
63
+ }
64
+ ],
65
+ "test_data": "# Test Customers\ntest_customer_1 = Customer(id=1, name=\"Customer A\", credit_limit=5000, balance=0)\ntest_customer_2 = Customer(id=2, name=\"Customer B\", credit_limit=6000, balance=0)\ntest_customer_3 = Customer(id=3, name=\"Customer C\", credit_limit=7000, balance=0)\ntest_customer_4 = Customer(id=4, name=\"Customer D\", credit_limit=8000, balance=0)\n\n# Test Products\ntest_product_1 = Product(id=1, unit_price=10)\ntest_product_2 = Product(id=2, unit_price=15)\ntest_product_3 = Product(id=3, unit_price=20)\ntest_product_4 = Product(id=4, unit_price=25)\n\n# Test Orders\ntest_order_1 = Order(id=1, customer_id=1, date_shipped=None, amount_total=0, notes=\"First order\")\ntest_order_2 = Order(id=2, customer_id=2, date_shipped=None, amount_total=0, notes=\"Second order\")\ntest_order_3 = Order(id=3, customer_id=3, date_shipped=None, amount_total=0, notes=\"Third order\")\ntest_order_4 = Order(id=4, customer_id=4, date_shipped=None, amount_total=0, notes=\"Fourth order\")\n\n# Test Items\ntest_item_1 = Item(id=1, order_id=1, product_id=1, quantity=2, unit_price=10, amount=20)\ntest_item_2 = Item(id=2, order_id=2, product_id=2, quantity=3, unit_price=15, amount=45)\ntest_item_3 = Item(id=3, order_id=3, product_id=3, quantity=4, unit_price=20, amount=80)\ntest_item_4 = Item(id=4, order_id=4, product_id=4, quantity=5, unit_price=25, amount=125)",
66
+ "test_data_rows": [
67
+ {
68
+ "test_data_row_variable": "test_customer_1",
69
+ "code": "test_customer_1 = Customer(id=1, name=\"Customer A\", credit_limit=5000, balance=0)"
70
+ },
71
+ {
72
+ "test_data_row_variable": "test_customer_2",
73
+ "code": "test_customer_2 = Customer(id=2, name=\"Customer B\", credit_limit=6000, balance=0)"
74
+ },
75
+ {
76
+ "test_data_row_variable": "test_customer_3",
77
+ "code": "test_customer_3 = Customer(id=3, name=\"Customer C\", credit_limit=7000, balance=0)"
78
+ },
79
+ {
80
+ "test_data_row_variable": "test_customer_4",
81
+ "code": "test_customer_4 = Customer(id=4, name=\"Customer D\", credit_limit=8000, balance=0)"
82
+ },
83
+ {
84
+ "test_data_row_variable": "test_product_1",
85
+ "code": "test_product_1 = Product(id=1, unit_price=10)"
86
+ },
87
+ {
88
+ "test_data_row_variable": "test_product_2",
89
+ "code": "test_product_2 = Product(id=2, unit_price=15)"
90
+ },
91
+ {
92
+ "test_data_row_variable": "test_product_3",
93
+ "code": "test_product_3 = Product(id=3, unit_price=20)"
94
+ },
95
+ {
96
+ "test_data_row_variable": "test_product_4",
97
+ "code": "test_product_4 = Product(id=4, unit_price=25)"
98
+ },
99
+ {
100
+ "test_data_row_variable": "test_order_1",
101
+ "code": "test_order_1 = Order(id=1, customer_id=1, date_shipped=None, amount_total=0, notes=\"First order\")"
102
+ },
103
+ {
104
+ "test_data_row_variable": "test_order_2",
105
+ "code": "test_order_2 = Order(id=2, customer_id=2, date_shipped=None, amount_total=0, notes=\"Second order\")"
106
+ },
107
+ {
108
+ "test_data_row_variable": "test_order_3",
109
+ "code": "test_order_3 = Order(id=3, customer_id=3, date_shipped=None, amount_total=0, notes=\"Third order\")"
110
+ },
111
+ {
112
+ "test_data_row_variable": "test_order_4",
113
+ "code": "test_order_4 = Order(id=4, customer_id=4, date_shipped=None, amount_total=0, notes=\"Fourth order\")"
114
+ },
115
+ {
116
+ "test_data_row_variable": "test_item_1",
117
+ "code": "test_item_1 = Item(id=1, order_id=1, product_id=1, quantity=2, unit_price=10, amount=20)"
118
+ },
119
+ {
120
+ "test_data_row_variable": "test_item_2",
121
+ "code": "test_item_2 = Item(id=2, order_id=2, product_id=2, quantity=3, unit_price=15, amount=45)"
122
+ },
123
+ {
124
+ "test_data_row_variable": "test_item_3",
125
+ "code": "test_item_3 = Item(id=3, order_id=3, product_id=3, quantity=4, unit_price=20, amount=80)"
126
+ },
127
+ {
128
+ "test_data_row_variable": "test_item_4",
129
+ "code": "test_item_4 = Item(id=4, order_id=4, product_id=4, quantity=5, unit_price=25, amount=125)"
130
+ }
131
+ ],
132
+ "test_data_sqlite": "-- Test Customers\nINSERT INTO customer (id, name, credit_limit, balance) VALUES (1, 'Customer A', 5000, 0);\nINSERT INTO customer (id, name, credit_limit, balance) VALUES (2, 'Customer B', 6000, 0);\nINSERT INTO customer (id, name, credit_limit, balance) VALUES (3, 'Customer C', 7000, 0);\nINSERT INTO customer (id, name, credit_limit, balance) VALUES (4, 'Customer D', 8000, 0);\n\n-- Test Products\nINSERT INTO product (id, unit_price) VALUES (1, 10);\nINSERT INTO product (id, unit_price) VALUES (2, 15);\nINSERT INTO product (id, unit_price) VALUES (3, 20);\nINSERT INTO product (id, unit_price) VALUES (4, 25);\n\n-- Test Orders\nINSERT INTO \"order\" (id, customer_id, date_shipped, amount_total, notes) VALUES (1, 1, NULL, 0, 'First order');\nINSERT INTO \"order\" (id, customer_id, date_shipped, amount_total, notes) VALUES (2, 2, NULL, 0, 'Second order');\nINSERT INTO \"order\" (id, customer_id, date_shipped, amount_total, notes) VALUES (3, 3, NULL, 0, 'Third order');\nINSERT INTO \"order\" (id, customer_id, date_shipped, amount_total, notes) VALUES (4, 4, NULL, 0, 'Fourth order');\n\n-- Test Items\nINSERT INTO item (id, order_id, product_id, quantity, unit_price, amount) VALUES (1, 1, 1, 2, 10, 20);\nINSERT INTO item (id, order_id, product_id, quantity, unit_price, amount) VALUES (2, 2, 2, 3, 15, 45);\nINSERT INTO item (id, order_id, product_id, quantity, unit_price, amount) VALUES (3, 3, 3, 4, 20, 80);\nINSERT INTO item (id, order_id, product_id, quantity, unit_price, amount) VALUES (4, 4, 4, 5, 25, 125);",
133
+ "name": "Order Management System"
134
+ }
@@ -0,0 +1,131 @@
1
+ Update the prior response - be sure not to lose classes and test data already created.
2
+
3
+ Provide a 10% discount when buying more than 10 carbon neutral products
4
+
5
+ The Item carbon neutral is copied from the Product carbon neutral
6
+
7
+ Hints: use autonum keys (for all tables - including for link/join/junction/intersection tables), allow nulls, foreign keys, no check constraints.
8
+
9
+ Be sure to create classes, never tables.
10
+
11
+ If you create sum, count or formula Logic Bank rules, then you MUST create a corresponding column in the data model.
12
+
13
+ Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
14
+ this means you can not enter string attributes where a date or datetime object is expected.
15
+
16
+ Don't install additional packages.
17
+ Don't use the faker pip package.
18
+
19
+ When creating SQLAlchemy data model classes, follow these guidelines carefully:
20
+ * Use foreign key columns instead of relationship names for the data.
21
+ * Do not specify nullable unless explicitly specified.
22
+ * Do not use unique unless explicitly specified.
23
+ * Do not use Float unless explicitly specified.
24
+ * Generate the classes ONLY.
25
+ * Do NOT generate imports.
26
+ * Do NOT generate connect statements.
27
+ * Do NOT generate engines.
28
+
29
+ Create 4 rows of test data for each table, and follow these guidelines carefully:
30
+ * Create separate objects for each test data row, not in arrays.
31
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on Logic Bank,
32
+ and do not generate db.execute statements.
33
+ * Do not create arrays of test data.
34
+ * Do not create a function to load test data.
35
+ * Do not print the test data.
36
+ * Use double quotes " for strings.
37
+ * For test data, format dates as date(year, month, day).
38
+
39
+ <responseFormat>
40
+ class Rule(BaseModel):
41
+ name: str
42
+ description: str
43
+ use_case: str # specified use case or requirement name (use 'General' if missing)
44
+ entity: str # the entity being constrained or derived
45
+ code: str # logicbank rule code
46
+
47
+ class Model(BaseModel):
48
+ classname: str
49
+ code: str # sqlalchemy model code
50
+ sqlite_create: str # sqlite create table statement
51
+ description: str
52
+ name: str
53
+
54
+ class TestDataRow(BaseModel):
55
+ test_data_row_variable: str # the Python test data row variable
56
+ code: str # Python code to create a test data row instance
57
+
58
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
59
+ # response: str # result
60
+ models : List[Model] # list of sqlalchemy classes in the response
61
+ rules : List[Rule] # list rule declarations
62
+ test_data: str
63
+ test_data_rows: List[TestDataRow] # list of test data rows
64
+ test_data_sqlite: str # test data as sqlite INSERT statements
65
+ name: str # suggest a short name for the project
66
+
67
+ Format the response as a WGResult.
68
+
69
+ </responseFormat>
70
+
71
+ <responseFormat>
72
+
73
+ class Rule(BaseModel):
74
+
75
+ name: str
76
+
77
+ description: str
78
+
79
+ use_case: str # specified use case or requirement name (use 'General' if missing)
80
+
81
+ entity: str # the entity being constrained or derived
82
+
83
+ code: str # logicbank rule code
84
+
85
+
86
+
87
+ class Model(BaseModel):
88
+
89
+ classname: str
90
+
91
+ code: str # sqlalchemy model code
92
+
93
+ sqlite_create: str # sqlite create table statement
94
+
95
+ description: str
96
+
97
+ name: str
98
+
99
+
100
+
101
+ class TestDataRow(BaseModel):
102
+
103
+ test_data_row_variable: str # the Python test data row variable
104
+
105
+ code: str # Python code to create a test data row instance
106
+
107
+
108
+
109
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
110
+
111
+ # response: str # result
112
+
113
+ models : List[Model] # list of sqlalchemy classes in the response
114
+
115
+ rules : List[Rule] # list rule declarations
116
+
117
+ test_data: str
118
+
119
+ test_data_rows: List[TestDataRow] # list of test data rows
120
+
121
+ test_data_sqlite: str # test data as sqlite INSERT statements
122
+
123
+ name: str # suggest a short name for the project
124
+
125
+
126
+
127
+ Format the response as a WGResult.
128
+
129
+
130
+
131
+ </responseFormat>
@@ -0,0 +1,141 @@
1
+ {
2
+ "models": [
3
+ {
4
+ "classname": "Customer",
5
+ "code": "class Customer(Base):\n __tablename__ = 'customer'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String(8000), unique=True)\n balance = Column(DECIMAL)\n credit_limit = Column(DECIMAL)",
6
+ "description": "Class representing customers with unique names and credit limits.",
7
+ "name": "Customer"
8
+ },
9
+ {
10
+ "classname": "Order",
11
+ "code": "class Order(Base):\n __tablename__ = 'order'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n customer_id = Column(Integer, ForeignKey('customer.id'))\n amount_total = Column(DECIMAL)\n date_shipped = Column(DateTime)\n notes = Column(String(8000))",
12
+ "description": "Class representing orders linked to customers, with notes and shipment date.",
13
+ "name": "Order"
14
+ },
15
+ {
16
+ "classname": "Item",
17
+ "code": "class Item(Base):\n __tablename__ = 'item'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n order_id = Column(Integer, ForeignKey('order.id'))\n product_id = Column(Integer, ForeignKey('product.id'))\n quantity = Column(Integer, nullable=False)\n amount = Column(DECIMAL)\n unit_price = Column(DECIMAL)\n carbon_neutral = Column(Boolean)",
18
+ "description": "Class representing items with quantity, amount, and carbon neutral status.",
19
+ "name": "Item"
20
+ },
21
+ {
22
+ "classname": "Product",
23
+ "code": "class Product(Base):\n __tablename__ = 'product'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String(8000))\n unit_price = Column(DECIMAL)\n carbon_neutral = Column(Boolean)",
24
+ "description": "Class representing products with their unit prices and carbon neutral status.",
25
+ "name": "Product"
26
+ }
27
+ ],
28
+ "rules": [
29
+ {
30
+ "name": "Customer Balance Sum",
31
+ "description": "Customer's balance is the sum of the Order amount_total where date_shipped is null.",
32
+ "use_case": "Check Credit",
33
+ "entity": "Customer",
34
+ "code": "Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)"
35
+ },
36
+ {
37
+ "name": "Order Amount Total",
38
+ "description": "The Order's amount_total is the sum of the Item amount.",
39
+ "use_case": "Check Credit",
40
+ "entity": "Order",
41
+ "code": "Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)"
42
+ },
43
+ {
44
+ "name": "Item Amount Formula",
45
+ "description": "The Item amount is the quantity * unit_price.",
46
+ "use_case": "Check Credit",
47
+ "entity": "Item",
48
+ "code": "Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price if not row.carbon_neutral or row.quantity <= 10 else 0.9 * row.quantity * row.unit_price)"
49
+ },
50
+ {
51
+ "name": "Item Unit Price Copy",
52
+ "description": "The Item unit_price is copied from the Product unit_price.",
53
+ "use_case": "Check Credit",
54
+ "entity": "Item",
55
+ "code": "Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)"
56
+ },
57
+ {
58
+ "name": "Customer Credit Constraint",
59
+ "description": "The Customer's balance must be less than the credit limit.",
60
+ "use_case": "Check Credit",
61
+ "entity": "Customer",
62
+ "code": "Rule.constraint(validate=Customer, as_condition=lambda row: row.balance <= row.credit_limit, error_msg='Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})')"
63
+ },
64
+ {
65
+ "name": "Item Carbon Neutral Copy",
66
+ "description": "Copy carbon neutral status from Product to Item.",
67
+ "use_case": "General",
68
+ "entity": "Item",
69
+ "code": "Rule.copy(derive=Item.carbon_neutral, from_parent=Product.carbon_neutral)"
70
+ }
71
+ ],
72
+ "test_data": "Sample test data includes initial customers, orders with associated items, and products.",
73
+ "test_data_rows": [
74
+ {
75
+ "test_data_row_variable": "customer1",
76
+ "code": "customer1 = Customer(id=1, name=\"Customer A\", balance=0.0, credit_limit=1000.0)"
77
+ },
78
+ {
79
+ "test_data_row_variable": "customer2",
80
+ "code": "customer2 = Customer(id=2, name=\"Customer B\", balance=0.0, credit_limit=1500.0)"
81
+ },
82
+ {
83
+ "test_data_row_variable": "customer3",
84
+ "code": "customer3 = Customer(id=3, name=\"Customer C\", balance=0.0, credit_limit=2000.0)"
85
+ },
86
+ {
87
+ "test_data_row_variable": "customer4",
88
+ "code": "customer4 = Customer(id=4, name=\"Customer D\", balance=0.0, credit_limit=2500.0)"
89
+ },
90
+ {
91
+ "test_data_row_variable": "product1",
92
+ "code": "product1 = Product(id=1, name=\"Product A\", unit_price=10.0, carbon_neutral=True)"
93
+ },
94
+ {
95
+ "test_data_row_variable": "product2",
96
+ "code": "product2 = Product(id=2, name=\"Product B\", unit_price=20.0, carbon_neutral=False)"
97
+ },
98
+ {
99
+ "test_data_row_variable": "product3",
100
+ "code": "product3 = Product(id=3, name=\"Product C\", unit_price=30.0, carbon_neutral=True)"
101
+ },
102
+ {
103
+ "test_data_row_variable": "product4",
104
+ "code": "product4 = Product(id=4, name=\"Product D\", unit_price=40.0, carbon_neutral=False)"
105
+ },
106
+ {
107
+ "test_data_row_variable": "order1",
108
+ "code": "order1 = Order(id=1, customer_id=1, amount_total=0.0, date_shipped=None, notes='Urgent order')"
109
+ },
110
+ {
111
+ "test_data_row_variable": "order2",
112
+ "code": "order2 = Order(id=2, customer_id=2, amount_total=0.0, date_shipped=None, notes='Regular order')"
113
+ },
114
+ {
115
+ "test_data_row_variable": "order3",
116
+ "code": "order3 = Order(id=3, customer_id=3, amount_total=0.0, date_shipped=None, notes='Delayed order')"
117
+ },
118
+ {
119
+ "test_data_row_variable": "order4",
120
+ "code": "order4 = Order(id=4, customer_id=4, amount_total=0.0, date_shipped=None, notes='Important client')"
121
+ },
122
+ {
123
+ "test_data_row_variable": "item1",
124
+ "code": "item1 = Item(id=1, order_id=1, product_id=1, quantity=15, amount=135.0, unit_price=10.0, carbon_neutral=True)"
125
+ },
126
+ {
127
+ "test_data_row_variable": "item2",
128
+ "code": "item2 = Item(id=2, order_id=1, product_id=2, quantity=5, amount=100.0, unit_price=20.0, carbon_neutral=False)"
129
+ },
130
+ {
131
+ "test_data_row_variable": "item3",
132
+ "code": "item3 = Item(id=3, order_id=2, product_id=3, quantity=8, amount=216.0, unit_price=30.0, carbon_neutral=True)"
133
+ },
134
+ {
135
+ "test_data_row_variable": "item4",
136
+ "code": "item4 = Item(id=4, order_id=3, product_id=4, quantity=2, amount=80.0, unit_price=40.0, carbon_neutral=False)"
137
+ }
138
+ ],
139
+ "test_data_sqlite": "INSERT INTO customer (id, name, balance, credit_limit) VALUES\n(1, \"Customer A\", 0.0, 1000.0),\n(2, \"Customer B\", 0.0, 1500.0),\n(3, \"Customer C\", 0.0, 2000.0),\n(4, \"Customer D\", 0.0, 2500.0);\n\nINSERT INTO product (id, name, unit_price, carbon_neutral) VALUES\n(1, \"Product A\", 10.0, 1),\n(2, \"Product B\", 20.0, 0),\n(3, \"Product C\", 30.0, 1),\n(4, \"Product D\", 40.0, 0);\n\nINSERT INTO \"order\" (id, customer_id, amount_total, date_shipped, notes) VALUES\n(1, 1, 0.0, NULL, 'Urgent order'),\n(2, 2, 0.0, NULL, 'Regular order'),\n(3, 3, 0.0, NULL, 'Delayed order'),\n(4, 4, 0.0, NULL, 'Important client');\n\nINSERT INTO item (id, order_id, product_id, quantity, amount, unit_price, carbon_neutral) VALUES\n(1, 1, 1, 15, 135.0, 10.0, 1),\n(2, 1, 2, 5, 100.0, 20.0, 0),\n(3, 2, 3, 8, 216.0, 30.0, 1),\n(4, 3, 4, 2, 80.0, 40.0, 0);",
140
+ "name": "CustomerOrderSystem"
141
+ }
@@ -0,0 +1,105 @@
1
+ # using resolved_model self.resolved_model FIXME
2
+ # created from response, to create create_db_models.sqlite, with test data
3
+ # that is used to create project
4
+ # should run without error in manager
5
+ # if not, check for decimal, indent, or import issues
6
+
7
+ import decimal
8
+ import logging
9
+ import sqlalchemy
10
+ from sqlalchemy.sql import func
11
+ from logic_bank.logic_bank import Rule
12
+ from sqlalchemy import create_engine, Column, Integer, String, Float, ForeignKey, Date, DateTime, Numeric, Boolean, Text, DECIMAL
13
+ from sqlalchemy.types import *
14
+ from sqlalchemy.ext.declarative import declarative_base
15
+ from sqlalchemy.orm import sessionmaker
16
+ from sqlalchemy.orm import relationship
17
+ from sqlalchemy.orm import Mapped
18
+ from datetime import date
19
+ from datetime import datetime
20
+ from typing import List
21
+
22
+
23
+ logging.getLogger('sqlalchemy.engine.Engine').disabled = True # remove for additional logging
24
+
25
+ Base = declarative_base() # from system/genai/create_db_models_inserts/create_db_models_prefix.py
26
+
27
+
28
+ from sqlalchemy.dialects.sqlite import *
29
+
30
+ class CustomerAccount(Base):
31
+ """description: This table holds customer account details with credit checks."""
32
+ """
33
+ description: This table holds customer account details with credit checks.
34
+ """
35
+ __tablename__ = 'customer_account'
36
+ id = Column(Integer, primary_key=True, autoincrement=True)
37
+ name = Column(String, nullable=True)
38
+ email = Column(String, nullable=True)
39
+ balance = Column(Float, nullable=True)
40
+ credit_limit = Column(Float, nullable=True)
41
+
42
+ class Address(Base):
43
+ """description: This table contains addresses associated with CustomerAccount."""
44
+ """
45
+ description: This table contains addresses associated with CustomerAccount.
46
+ """
47
+ __tablename__ = 'address'
48
+ id = Column(Integer, primary_key=True, autoincrement=True)
49
+ customer_account_id = Column(Integer, ForeignKey('customer_account.id'),
50
+ nullable=False)
51
+ street = Column(String, nullable=True)
52
+ city = Column(String, nullable=True)
53
+ state = Column(String, nullable=True)
54
+ zip_code = Column(String, nullable=True)
55
+
56
+ class SalesRep(Base):
57
+ """description: This table contains sales representative details."""
58
+ """
59
+ description: This table contains sales representative details.
60
+ """
61
+ __tablename__ = 'sales_rep'
62
+ id = Column(Integer, primary_key=True, autoincrement=True)
63
+ name = Column(String, nullable=True)
64
+ region = Column(String, nullable=True)
65
+
66
+ class Order(Base):
67
+ """description: This table contains order details with an assigned sales representative."""
68
+ """
69
+ description: This table contains order details with an assigned sales representative.
70
+ """
71
+ __tablename__ = 'order'
72
+ id = Column(Integer, primary_key=True, autoincrement=True)
73
+ customer_account_id = Column(Integer, ForeignKey('customer_account.id'),
74
+ nullable=False)
75
+ order_date = Column(Date, nullable=True)
76
+ sales_rep_id = Column(Integer, ForeignKey('sales_rep.id'), nullable=False)
77
+ notes = Column(String, nullable=True)
78
+ amount_total = Column(Float, nullable=True)
79
+
80
+ class Item(Base):
81
+ """description: This table links orders to products for each item on an order."""
82
+ """
83
+ description: This table links orders to products for each item on an order.
84
+ """
85
+ __tablename__ = 'item'
86
+ id = Column(Integer, primary_key=True, autoincrement=True)
87
+ order_id = Column(Integer, ForeignKey('order.id'), nullable=False)
88
+ product_id = Column(Integer, ForeignKey('product.id'), nullable=False)
89
+ quantity = Column(Integer, nullable=True)
90
+ unit_price = Column(Float, nullable=True)
91
+ amount = Column(Float, nullable=True)
92
+
93
+ class Product(Base):
94
+ """description: This table contains product information."""
95
+ """
96
+ description: This table contains product information.
97
+ """
98
+ __tablename__ = 'product'
99
+ id = Column(Integer, primary_key=True, autoincrement=True)
100
+ name = Column(String, nullable=True)
101
+ price = Column(Float, nullable=True)
102
+
103
+
104
+ # end of model classes
105
+
@@ -0,0 +1,70 @@
1
+ // Copy this text, paste to https://dbdiagram.io/d
2
+ // Or, https://databasediagram.com/app
3
+ // Or, view in VSCode with extension: "DBML Live Preview"
4
+
5
+ Project DBML {
6
+ Note: '''
7
+ Address: This table contains addresses associated with CustomerAccount.
8
+ CustomerAccount: This table holds customer account details with credit checks.
9
+ Item: This table links orders to products for each item on an order.
10
+ Order: This table contains order details with an assigned sales representative.
11
+ Product: This table contains product information.
12
+ SalesRep: This table contains sales representative details.
13
+ '''
14
+ }
15
+
16
+ Table Address {
17
+ id INTEGER [primary key]
18
+ customer_account_id INTEGER
19
+ street VARCHAR
20
+ city VARCHAR
21
+ state VARCHAR
22
+ zip_code VARCHAR
23
+ }
24
+
25
+ Table CustomerAccount {
26
+ id INTEGER [primary key]
27
+ name VARCHAR
28
+ email VARCHAR
29
+ balance FLOAT
30
+ credit_limit FLOAT
31
+ }
32
+
33
+ Table Item {
34
+ id INTEGER [primary key]
35
+ order_id INTEGER
36
+ product_id INTEGER
37
+ quantity INTEGER
38
+ unit_price FLOAT
39
+ amount FLOAT
40
+ }
41
+
42
+ Table Order {
43
+ id INTEGER [primary key]
44
+ customer_account_id INTEGER
45
+ order_date DATE
46
+ sales_rep_id INTEGER
47
+ notes VARCHAR
48
+ amount_total FLOAT
49
+ }
50
+
51
+ Table Product {
52
+ id INTEGER [primary key]
53
+ name VARCHAR
54
+ price FLOAT
55
+ }
56
+
57
+ Table SalesRep {
58
+ id INTEGER [primary key]
59
+ name VARCHAR
60
+ region VARCHAR
61
+ }
62
+
63
+
64
+
65
+ // Relationships
66
+ Ref: Address.(customer_account_id) < CustomerAccount.(id)
67
+ Ref: Item.(order_id) < Order.(id)
68
+ Ref: Item.(product_id) < Product.(id)
69
+ Ref: Order.(customer_account_id) < CustomerAccount.(id)
70
+ Ref: Order.(sales_rep_id) < SalesRep.(id)
@@ -0,0 +1,6 @@
1
+ ## GenAI Notes
2
+
3
+ Review the [database diagram](https://apilogicserver.github.io/Docs/Database-Diagram/).
4
+
5
+ GenAI work files (exact prompts, with inserts) saved for iterations, diagnostics
6
+ See [WebGenAI-CLI](https://apilogicserver.github.io/Docs/WebGenAI-CLI/).