Remove inlined server crate (moved to komp_ac_server repo)
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
TEST_DATABASE_URL="postgres://multi_psql_dev:3@localhost:5432/multi_rust_test"
|
|
||||||
1
server/.gitignore
vendored
1
server/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
docs-prod/
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT id, columns FROM table_definitions\n WHERE profile_id = $1 AND table_name = $2",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "columns",
|
|
||||||
"type_info": "Jsonb"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "18494c5209588687b2339097eb7c27822246dc6c92a8bb6de976395e9271085f"
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT EXISTS(\n SELECT 1 FROM table_definitions\n WHERE profile_id = $1 AND table_name = $2\n )",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "exists",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "191c33c4b3f9acf81b7e78297bc1903bbaae8bbc3057a2469be202fdcb3c2945"
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT\n id,\n deleted,\n adresar_id,\n c_dokladu,\n datum as \"datum: chrono::NaiveDate\",\n c_faktury,\n obsah,\n stredisko,\n c_uctu,\n md,\n identif,\n poznanka,\n firma\n FROM uctovnictvo\n WHERE id = $1\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "adresar_id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "c_dokladu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "datum: chrono::NaiveDate",
|
|
||||||
"type_info": "Date"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "c_faktury",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "obsah",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "stredisko",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "c_uctu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 9,
|
|
||||||
"name": "md",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 10,
|
|
||||||
"name": "identif",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 11,
|
|
||||||
"name": "poznanka",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 12,
|
|
||||||
"name": "firma",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "32cedc121e80fd03dbcca056d5d43d7cfe104e06d570304e12ce7a86c13a41d1"
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "DELETE FROM table_definitions WHERE id = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "39d6176d6c3c4b647e4deb7cd7822a03c210ae5ec8a395f4fd3fb87dabe9ecc6"
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO table_definition_links\n (source_table_id, linked_table_id, is_required)\n VALUES ($1, $2, $3)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int8",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "41621bc47426b92c64e6dfc56f001ad47263b6eed93f5f68601746c4059db3f8"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT id \n FROM adresar \n WHERE deleted = FALSE \n ORDER BY id ASC \n OFFSET $1 \n LIMIT 1\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "454ca15c6207f1dc2fd24bec90f0835beee74a05d47765d7a41f9d8e77b658a4"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT COUNT(*) AS count\n FROM adresar\n WHERE deleted = FALSE\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "count",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": []
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "45746d148c51658e1262f0f88f003ec137f213cf2e7cff72080f0c7853a7cd43"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT ltd.table_name\n FROM table_definition_links tdl\n JOIN table_definitions ltd ON tdl.linked_table_id = ltd.id\n WHERE tdl.source_table_id = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "table_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "468bb5bb4fdaefcb4b280761d7880a556d40c172568ad3a1ed13156fbef72776"
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n INSERT INTO users (username, email, password_hash, role)\n VALUES ($1, $2, $3, 'accountant')\n RETURNING id, username, email, role\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "username",
|
|
||||||
"type_info": "Varchar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "email",
|
|
||||||
"type_info": "Varchar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "role",
|
|
||||||
"type_info": "Varchar"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Varchar",
|
|
||||||
"Varchar"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "48d0a6d393dac121bfa4230830a105aede2179b07395f97750ab2fa1970afacd"
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n INSERT INTO uctovnictvo (\n adresar_id, c_dokladu, datum, c_faktury, obsah, stredisko,\n c_uctu, md, identif, poznanka, firma, deleted\n )\n VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12\n )\n RETURNING\n id,\n deleted,\n adresar_id,\n c_dokladu,\n datum as \"datum: chrono::NaiveDate\",\n c_faktury,\n obsah,\n stredisko,\n c_uctu,\n md,\n identif,\n poznanka,\n firma\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "adresar_id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "c_dokladu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "datum: chrono::NaiveDate",
|
|
||||||
"type_info": "Date"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "c_faktury",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "obsah",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "stredisko",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "c_uctu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 9,
|
|
||||||
"name": "md",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 10,
|
|
||||||
"name": "identif",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 11,
|
|
||||||
"name": "poznanka",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 12,
|
|
||||||
"name": "firma",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Date",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "58af461c82e5ed8ed4bab323b909c043143b4e521c9281c048df6a505c9ac020"
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT id FROM table_definitions \n WHERE profile_id = $1 AND table_name = $2",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "5e0c1a07987fcdbcca9878e2f4a0c95cee65cae4cc036e99f01d92c17236e038"
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT id, password_hash, role\n FROM users\n WHERE username = $1 OR email = $1\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "password_hash",
|
|
||||||
"type_info": "Varchar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "role",
|
|
||||||
"type_info": "Varchar"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "6be0bb23ad1ba85add309f6e4f55495a5d248901fb0d23fea908815747a0bd50"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT id FROM profiles WHERE name = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7600fd56765577629232ab785bad61637faf3a11af43902577a3905fbb767c1f"
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT id, name FROM profiles",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "name",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": []
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7619fb9209a4d9388616bcb9a3d083a61b5f00f1dd04230320241d91ced15296"
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT id FROM table_definitions\n WHERE profile_id = $1 AND table_name = $2",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "792d886a32bc6b6b7ca27ad347e96ff4ae66a4b8da8185dfb27b9d883e068c43"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT COUNT(*) as count FROM table_definitions WHERE profile_id = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "count",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7b1b134886c98c0b897cacb13d6e4614f6473f7f8fd18b1443713437e4493896"
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT table_name FROM table_definitions\n WHERE profile_id = $1 AND table_name LIKE $2",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "table_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "80f0f7f9ab12a8fe07ea71b548d27bcd6253b598ac4486b72b3d960f03df47f3"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT COUNT(*) AS count\n FROM uctovnictvo\n WHERE deleted = FALSE\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "count",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": []
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "8c2686d3882f535b7af3f75881ab7ee5ded9ae1b3112f841e95d6508af1fd0f8"
|
|
||||||
}
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n INSERT INTO adresar (\n firma, kz, drc, ulica, psc, mesto, stat, banka, ucet,\n skladm, ico, kontakt, telefon, skladu, fax, deleted\n )\n VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9,\n $10, $11, $12, $13, $14, $15, $16\n )\n RETURNING\n id, deleted, firma, kz, drc, ulica, psc, mesto, stat,\n banka, ucet, skladm, ico, kontakt, telefon, skladu, fax\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "firma",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "kz",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "drc",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "ulica",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "psc",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "mesto",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "stat",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 9,
|
|
||||||
"name": "banka",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 10,
|
|
||||||
"name": "ucet",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 11,
|
|
||||||
"name": "skladm",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 12,
|
|
||||||
"name": "ico",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 13,
|
|
||||||
"name": "kontakt",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 14,
|
|
||||||
"name": "telefon",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 15,
|
|
||||||
"name": "skladu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 16,
|
|
||||||
"name": "fax",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "95c824caa712cecb40992af93eaed0fb601c208cb7a43f6df31ebc4c7e96a572"
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "DELETE FROM profiles WHERE id = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "990c9f644bc8f229b1be87f7a6a5dd8fdc2935758561b94e62e661fd03cb92d8"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT id\n FROM uctovnictvo\n WHERE deleted = FALSE\n ORDER BY id ASC\n OFFSET $1\n LIMIT 1\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "a1270ca26e078fda3efdf1b30d24cdcef04b10bf36e6691dbfba5518ec6bd665"
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT id, table_name, columns, profile_id\n FROM table_definitions WHERE id = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "table_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "columns",
|
|
||||||
"type_info": "Jsonb"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "profile_id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "a466364aa022c2bae1a58f683ecdf390205e43da6b04f46a42820b2fff9e6a79"
|
|
||||||
}
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE adresar\n SET\n firma = $2,\n kz = $3,\n drc = $4,\n ulica = $5,\n psc = $6,\n mesto = $7,\n stat = $8,\n banka = $9,\n ucet = $10,\n skladm = $11,\n ico = $12,\n kontakt = $13,\n telefon = $14,\n skladu = $15,\n fax = $16\n WHERE id = $1 AND deleted = FALSE\n RETURNING\n id,\n deleted,\n firma,\n kz,\n drc,\n ulica,\n psc,\n mesto,\n stat,\n banka,\n ucet,\n skladm,\n ico,\n kontakt,\n telefon,\n skladu,\n fax\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "firma",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "kz",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "drc",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "ulica",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "psc",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "mesto",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "stat",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 9,
|
|
||||||
"name": "banka",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 10,
|
|
||||||
"name": "ucet",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 11,
|
|
||||||
"name": "skladm",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 12,
|
|
||||||
"name": "ico",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 13,
|
|
||||||
"name": "kontakt",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 14,
|
|
||||||
"name": "telefon",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 15,
|
|
||||||
"name": "skladu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 16,
|
|
||||||
"name": "fax",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "abbc5cf0972031d4e1a5508fe8ef7fc42609c71fd207ddf7c64eadb56edec66d"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO profiles (name) VALUES ($1)\n ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name\n RETURNING id",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "b1e2fbffc7e6af1857e786ed28b2a0e6b99ff039f2f3cc9bf2b08fa22d678a83"
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT target_column, script FROM table_scripts WHERE table_definitions_id = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "target_column",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "script",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "b519307ed5b2dba41c37845f23f9abff35312b62cf05ef2e8c5faa4ab0b0c194"
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO table_scripts\n (table_definitions_id, target_table, target_column,\n target_column_type, script, description, profile_id)\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n RETURNING id",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "c07a8511e5f32bf230240b28cb292d40f862b6ec58883f21ee8e1937860585d6"
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT\n id,\n deleted,\n firma,\n kz,\n drc,\n ulica,\n psc,\n mesto,\n stat,\n banka,\n ucet,\n skladm,\n ico,\n kontakt,\n telefon,\n skladu,\n fax\n FROM adresar\n WHERE id = $1 AND deleted = false\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "firma",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "kz",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "drc",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "ulica",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "psc",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "mesto",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "stat",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 9,
|
|
||||||
"name": "banka",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 10,
|
|
||||||
"name": "ucet",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 11,
|
|
||||||
"name": "skladm",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 12,
|
|
||||||
"name": "ico",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 13,
|
|
||||||
"name": "kontakt",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 14,
|
|
||||||
"name": "telefon",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 15,
|
|
||||||
"name": "skladu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 16,
|
|
||||||
"name": "fax",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "c0cac8460d90bfedd1a94d30020d10ac0e1c8e769b6b85a7112ec9ed3cabb21d"
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT 1 AS exists FROM table_definitions\n WHERE profile_id = $1 AND table_name = $2",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "exists",
|
|
||||||
"type_info": "Int4"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "c380148ff87cf4bd4535f118d064bf39db63a318eedf8d3d21ae6f4856bb0655"
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO table_definitions\n (profile_id, table_name, columns, indexes)\n VALUES ($1, $2, $3, $4)\n RETURNING id",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Jsonb",
|
|
||||||
"Jsonb"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "d1579b19c2b04abd5b58c5ea39f740e403917db736c94e4054d04f8c9509f57a"
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT\n td.table_name,\n COALESCE(\n json_agg(\n json_build_object(\n 'linked_name', ltd.table_name,\n 'required', tdl.is_required\n )\n ) FILTER (WHERE ltd.id IS NOT NULL),\n '[]'\n ) as dependencies\n FROM table_definitions td\n LEFT JOIN table_definition_links tdl ON td.id = tdl.source_table_id\n LEFT JOIN table_definitions ltd ON tdl.linked_table_id = ltd.id\n WHERE td.profile_id = $1\n GROUP BY td.table_name\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "table_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "dependencies",
|
|
||||||
"type_info": "Json"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "e23802d20f7f929810f5d294a36d23eca89d4abf6aa7d7d4b4fee9147e153b57"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT table_name FROM table_definitions WHERE id = $1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "table_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "e6ef405614c7499ee6e25cdc3811cc0e90bc7592ce7dc35673039b5978ffbb6b"
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE adresar\n SET deleted = true\n WHERE id = $1 AND deleted = false\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "e9dcf08c2bedd88853dd6bd964b9808070cc19fe9043e19d9b1a41de8461cad2"
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE uctovnictvo\n SET\n adresar_id = $2,\n c_dokladu = $3,\n datum = $4,\n c_faktury = $5,\n obsah = $6,\n stredisko = $7,\n c_uctu = $8,\n md = $9,\n identif = $10,\n poznanka = $11,\n firma = $12\n WHERE id = $1 AND deleted = FALSE\n RETURNING\n id,\n deleted,\n adresar_id,\n c_dokladu,\n datum as \"datum: chrono::NaiveDate\",\n c_faktury,\n obsah,\n stredisko,\n c_uctu,\n md,\n identif,\n poznanka,\n firma\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "adresar_id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "c_dokladu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "datum: chrono::NaiveDate",
|
|
||||||
"type_info": "Date"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "c_faktury",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "obsah",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "stredisko",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "c_uctu",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 9,
|
|
||||||
"name": "md",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 10,
|
|
||||||
"name": "identif",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 11,
|
|
||||||
"name": "poznanka",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 12,
|
|
||||||
"name": "firma",
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Date",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "f8c18698e875c4b38e80d034e345621d79b0bbedb0c5113677110ca18acdc438"
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "server"
|
|
||||||
version.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license = "AGPL-3.0-or-later"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
common = { path = "../common" }
|
|
||||||
search = { path = "../search" }
|
|
||||||
|
|
||||||
anyhow = { workspace = true }
|
|
||||||
tantivy = { workspace = true }
|
|
||||||
prost = "0.13.5"
|
|
||||||
prost-types = { workspace = true }
|
|
||||||
chrono = { version = "0.4.40", features = ["serde"] }
|
|
||||||
dotenvy = "0.15.7"
|
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
|
||||||
serde_json = "1.0.140"
|
|
||||||
sqlx = { version = "0.8.5", features = ["chrono", "postgres", "runtime-tokio", "runtime-tokio-native-tls", "rust_decimal", "time", "uuid"] }
|
|
||||||
tokio = { version = "1.44.2", features = ["full", "macros"] }
|
|
||||||
tonic = "0.13.0"
|
|
||||||
tonic-reflection = "0.13.0"
|
|
||||||
tracing = "0.1.41"
|
|
||||||
time = { version = "0.3.41", features = ["local-offset"] }
|
|
||||||
|
|
||||||
steel-derive = "0.6.0"
|
|
||||||
steel-core = { version = "0.7.0", features = ["anyhow", "dylibs", "sync"] }
|
|
||||||
|
|
||||||
dashmap = "6.1.0"
|
|
||||||
lazy_static = "1.5.0"
|
|
||||||
bcrypt = "0.17.0"
|
|
||||||
validator = { version = "0.20.0", features = ["derive"] }
|
|
||||||
uuid = { version = "1.16.0", features = ["serde", "v4"] }
|
|
||||||
jsonwebtoken = "9.3.1"
|
|
||||||
rust-stemmers = "1.2.0"
|
|
||||||
|
|
||||||
rust_decimal = { workspace = true }
|
|
||||||
rust_decimal_macros = { workspace = true }
|
|
||||||
regex = { workspace = true }
|
|
||||||
thiserror = { workspace = true }
|
|
||||||
steel-decimal = "1.0.0"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
prost-build = "0.14.1"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "server"
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
tokio = { version = "1.44", features = ["full", "test-util"] }
|
|
||||||
rstest = "0.25.0"
|
|
||||||
lazy_static = "1.5.0"
|
|
||||||
rand = "0.9.1"
|
|
||||||
futures = "0.3.31"
|
|
||||||
tokio-test = "0.4.4"
|
|
||||||
661
server/LICENSE
661
server/LICENSE
@@ -1,661 +0,0 @@
|
|||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 19 November 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU Affero General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works, specifically designed to ensure
|
|
||||||
cooperation with the community in the case of network server software.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
our General Public Licenses are intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights
|
|
||||||
with two steps: (1) assert copyright on the software, and (2) offer
|
|
||||||
you this License which gives you legal permission to copy, distribute
|
|
||||||
and/or modify the software.
|
|
||||||
|
|
||||||
A secondary benefit of defending all users' freedom is that
|
|
||||||
improvements made in alternate versions of the program, if they
|
|
||||||
receive widespread use, become available for other developers to
|
|
||||||
incorporate. Many developers of free software are heartened and
|
|
||||||
encouraged by the resulting cooperation. However, in the case of
|
|
||||||
software used on network servers, this result may fail to come about.
|
|
||||||
The GNU General Public License permits making a modified version and
|
|
||||||
letting the public access it on a server without ever releasing its
|
|
||||||
source code to the public.
|
|
||||||
|
|
||||||
The GNU Affero General Public License is designed specifically to
|
|
||||||
ensure that, in such cases, the modified source code becomes available
|
|
||||||
to the community. It requires the operator of a network server to
|
|
||||||
provide the source code of the modified version running there to the
|
|
||||||
users of that server. Therefore, public use of a modified version, on
|
|
||||||
a publicly accessible server, gives the public access to the source
|
|
||||||
code of the modified version.
|
|
||||||
|
|
||||||
An older license, called the Affero General Public License and
|
|
||||||
published by Affero, was designed to accomplish similar goals. This is
|
|
||||||
a different license, not a version of the Affero GPL, but Affero has
|
|
||||||
released a new version of the Affero GPL which permits relicensing under
|
|
||||||
this license.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, if you modify the
|
|
||||||
Program, your modified version must prominently offer all users
|
|
||||||
interacting with it remotely through a computer network (if your version
|
|
||||||
supports such interaction) an opportunity to receive the Corresponding
|
|
||||||
Source of your version by providing access to the Corresponding Source
|
|
||||||
from a network server at no charge, through some standard or customary
|
|
||||||
means of facilitating copying of software. This Corresponding Source
|
|
||||||
shall include the Corresponding Source for any work covered by version 3
|
|
||||||
of the GNU General Public License that is incorporated pursuant to the
|
|
||||||
following paragraph.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the work with which it is combined will remain governed by version
|
|
||||||
3 of the GNU General Public License.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU Affero General Public License from time to time. Such new versions
|
|
||||||
will be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU Affero General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU Affero General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU Affero General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If your software can interact with users remotely through a computer
|
|
||||||
network, you should also make sure that it provides a way for users to
|
|
||||||
get its source. For example, if your program is a web application, its
|
|
||||||
interface could display a "Source" link that leads users to an archive
|
|
||||||
of the code. There are many ways you could offer source, and different
|
|
||||||
solutions will be better for different programs; see section 13 for the
|
|
||||||
specific requirements.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# Makefile
|
|
||||||
|
|
||||||
test: reset_db run_tests
|
|
||||||
|
|
||||||
reset_db:
|
|
||||||
@echo "Resetting test database..."
|
|
||||||
@./scripts/reset_test_db.sh
|
|
||||||
|
|
||||||
run_tests:
|
|
||||||
@echo "Running tests..."
|
|
||||||
@cargo test --test mod -- --test-threads=1
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 76 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 68 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 75 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 67 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB |
@@ -1,2 +0,0 @@
|
|||||||
DELETE FROM _sqlx_migrations WHERE version = 'number';
|
|
||||||
DROP TABLE table_name;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
DATABASE_URL=$(grep TEST_DATABASE_URL .env_test | cut -d '"' -f 2) sqlx migrate run
|
|
||||||
|
|
||||||
dont forget to apply migrations to the test database before proceeding to test
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
-- Add migration script here
|
|
||||||
CREATE TABLE schemas (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
name TEXT NOT NULL UNIQUE,
|
|
||||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
description TEXT,
|
|
||||||
is_active BOOLEAN DEFAULT TRUE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Create default profile for existing data
|
|
||||||
INSERT INTO schemas (name) VALUES ('default');
|
|
||||||
CREATE SCHEMA IF NOT EXISTS "default";
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
-- Main table definitions
|
|
||||||
|
|
||||||
CREATE TABLE table_definitions (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
table_name TEXT NOT NULL,
|
|
||||||
columns JSONB NOT NULL,
|
|
||||||
indexes JSONB NOT NULL,
|
|
||||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
schema_id BIGINT NOT NULL REFERENCES schemas(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Relationship table for multiple links
|
|
||||||
CREATE TABLE table_definition_links (
|
|
||||||
source_table_id BIGINT NOT NULL REFERENCES table_definitions(id) ON DELETE CASCADE,
|
|
||||||
linked_table_id BIGINT NOT NULL REFERENCES table_definitions(id),
|
|
||||||
is_required BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
PRIMARY KEY (source_table_id, linked_table_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Create composite unique index for schema+table combination
|
|
||||||
CREATE UNIQUE INDEX idx_table_definitions_schema_table
|
|
||||||
ON table_definitions (schema_id, table_name);
|
|
||||||
|
|
||||||
CREATE INDEX idx_links_source ON table_definition_links (source_table_id);
|
|
||||||
CREATE INDEX idx_links_target ON table_definition_links (linked_table_id);
|
|
||||||
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
-- Add migration script here
|
|
||||||
CREATE TABLE table_scripts (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
table_definitions_id BIGINT NOT NULL REFERENCES table_definitions(id),
|
|
||||||
target_table TEXT NOT NULL,
|
|
||||||
target_column TEXT NOT NULL,
|
|
||||||
target_column_type TEXT NOT NULL,
|
|
||||||
script TEXT NOT NULL,
|
|
||||||
description TEXT,
|
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
schema_id BIGINT NOT NULL REFERENCES schemas(id),
|
|
||||||
UNIQUE(table_definitions_id, target_column)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Add foreign key constraint
|
|
||||||
ALTER TABLE table_scripts
|
|
||||||
ADD CONSTRAINT fk_table_definition
|
|
||||||
FOREIGN KEY (table_definitions_id)
|
|
||||||
REFERENCES table_definitions(id);
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
-- Add migration script here
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
||||||
username VARCHAR(255) NOT NULL UNIQUE,
|
|
||||||
email VARCHAR(255) UNIQUE,
|
|
||||||
password_hash VARCHAR(255),
|
|
||||||
role VARCHAR(20) NOT NULL DEFAULT 'accountant',
|
|
||||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Add an index for faster lookups
|
|
||||||
CREATE INDEX idx_users_email_username ON users(email, username);
|
|
||||||
|
|
||||||
ALTER TABLE users
|
|
||||||
ADD CONSTRAINT valid_roles CHECK (role IN (
|
|
||||||
'admin',
|
|
||||||
'moderator',
|
|
||||||
'accountant',
|
|
||||||
'viewer'
|
|
||||||
));
|
|
||||||
|
|
||||||
-- Create JWT sessions table
|
|
||||||
CREATE TABLE user_sessions (
|
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
||||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
jwt_token TEXT NOT NULL UNIQUE,
|
|
||||||
expires_at TIMESTAMPTZ NOT NULL,
|
|
||||||
revoked BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Add indexes
|
|
||||||
CREATE INDEX idx_sessions_user ON user_sessions(user_id);
|
|
||||||
CREATE INDEX idx_sessions_expires ON user_sessions(expires_at);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
-- migrations/20250710201933_create_script_dependencies.sql
|
|
||||||
|
|
||||||
-- This table stores the dependency graph for table scripts
|
|
||||||
-- More efficient design with better indexing
|
|
||||||
CREATE TABLE script_dependencies (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
|
|
||||||
-- The script that creates this dependency
|
|
||||||
script_id BIGINT NOT NULL REFERENCES table_scripts(id) ON DELETE CASCADE,
|
|
||||||
|
|
||||||
-- The table that depends on another (source of dependency)
|
|
||||||
source_table_id BIGINT NOT NULL REFERENCES table_definitions(id) ON DELETE CASCADE,
|
|
||||||
|
|
||||||
-- The table being depended upon (target of dependency)
|
|
||||||
target_table_id BIGINT NOT NULL REFERENCES table_definitions(id) ON DELETE CASCADE,
|
|
||||||
|
|
||||||
-- What type of dependency (for better debugging)
|
|
||||||
dependency_type TEXT NOT NULL CHECK (dependency_type IN ('column_access', 'sql_query', 'indexed_access')),
|
|
||||||
|
|
||||||
-- Additional context (column name, query snippet, etc.)
|
|
||||||
context_info JSONB,
|
|
||||||
|
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Optimized indexes for fast cycle detection
|
|
||||||
CREATE INDEX idx_script_deps_source_target ON script_dependencies (source_table_id, target_table_id);
|
|
||||||
CREATE INDEX idx_script_deps_by_script ON script_dependencies (script_id);
|
|
||||||
CREATE INDEX idx_script_deps_by_target ON script_dependencies (target_table_id);
|
|
||||||
|
|
||||||
-- View for easy dependency analysis
|
|
||||||
CREATE VIEW dependency_graph AS
|
|
||||||
SELECT
|
|
||||||
sd.source_table_id,
|
|
||||||
sd.target_table_id,
|
|
||||||
st.table_name AS source_table,
|
|
||||||
tt.table_name AS target_table,
|
|
||||||
sd.dependency_type,
|
|
||||||
sd.context_info,
|
|
||||||
s.name AS schema_name
|
|
||||||
FROM script_dependencies sd
|
|
||||||
JOIN table_definitions st ON sd.source_table_id = st.id
|
|
||||||
JOIN table_definitions tt ON sd.target_table_id = tt.id
|
|
||||||
JOIN schemas s ON st.schema_id = s.id;
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
-- Add migration script here
|
|
||||||
|
|
||||||
CREATE TABLE table_validation_rules (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
table_def_id BIGINT NOT NULL
|
|
||||||
REFERENCES table_definitions(id)
|
|
||||||
ON DELETE CASCADE,
|
|
||||||
data_key TEXT NOT NULL,
|
|
||||||
config JSONB NOT NULL,
|
|
||||||
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
UNIQUE (table_def_id, data_key)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX idx_table_validation_rules_table
|
|
||||||
ON table_validation_rules (table_def_id);
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# scripts/reset_test_db.sh
|
|
||||||
|
|
||||||
# Load environment variables from .env_test if it exists
|
|
||||||
if [ -f .env_test ]; then
|
|
||||||
export $(grep -v '^#' .env_test | xargs)
|
|
||||||
fi
|
|
||||||
|
|
||||||
DATABASE_URL=${TEST_DATABASE_URL:-"postgres://multi_psql_dev:3@localhost:5432/multi_rust_test"}
|
|
||||||
echo "Resetting test DB at $DATABASE_URL"
|
|
||||||
|
|
||||||
# Check if database exists and who owns it
|
|
||||||
DB_NAME=$(echo "$DATABASE_URL" | sed 's|.*/||')
|
|
||||||
DB_HOST=$(echo "$DATABASE_URL" | sed 's|.*@||' | sed 's|:.*||')
|
|
||||||
DB_PORT=$(echo "$DATABASE_URL" | sed 's|.*:||' | sed 's|/.*||')
|
|
||||||
DB_USER=$(echo "$DATABASE_URL" | sed 's|.*://||' | sed 's|:.*||')
|
|
||||||
|
|
||||||
# Check database owner (optional info)
|
|
||||||
DB_OWNER=$(psql "$DATABASE_URL" -t -c "SELECT pg_catalog.pg_get_userbyid(d.datdba) FROM pg_catalog.pg_database d WHERE d.datname = '$DB_NAME';" 2>/dev/null | xargs)
|
|
||||||
if [ ! -z "$DB_OWNER" ]; then
|
|
||||||
echo "Database owner: $DB_OWNER"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Force drop database without confirmation
|
|
||||||
echo "Dropping database..."
|
|
||||||
sqlx database drop --database-url "$DATABASE_URL" --yes 2>/dev/null || {
|
|
||||||
# Fallback: use psql to force drop
|
|
||||||
psql "postgres://$DB_USER@$DB_HOST:$DB_PORT/postgres" -c "DROP DATABASE IF EXISTS \"$DB_NAME\";" 2>/dev/null || true
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create database
|
|
||||||
echo "Creating database..."
|
|
||||||
sqlx database create --database-url "$DATABASE_URL"
|
|
||||||
|
|
||||||
# Apply migrations
|
|
||||||
echo "Applying migrations..."
|
|
||||||
sqlx migrate run --database-url "$DATABASE_URL"
|
|
||||||
|
|
||||||
echo "✅ Test database reset and migrated."
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"username": "testuser2",
|
|
||||||
"email": "test2@example.com"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Register
|
|
||||||
{
|
|
||||||
"id": "5fa9bbce-85e0-4b06-8364-b561770c2fdd",
|
|
||||||
"username": "testuser2",
|
|
||||||
"email": "test2@example.com",
|
|
||||||
"role": "accountant"
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"username": "testuser3",
|
|
||||||
"email": "test3@example.com",
|
|
||||||
"password": "your_password",
|
|
||||||
"password_confirmation": "your_password"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Register
|
|
||||||
{
|
|
||||||
"id": "96d2fd35-b39d-4c05-916a-66134453d34c",
|
|
||||||
"username": "testuser3",
|
|
||||||
"email": "test3@example.com",
|
|
||||||
"role": "accountant"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"identifier": "testuser3"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Login
|
|
||||||
ERROR:
|
|
||||||
Code: Unauthenticated
|
|
||||||
Message: Invalid credentials
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"identifier": "testuser3",
|
|
||||||
"password": "your_password"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Login
|
|
||||||
{
|
|
||||||
"accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5NmQyZmQzNS1iMzlkLTRjMDUtOTE2YS02NjEzNDQ1M2QzNGMiLCJleHAiOjE3NDI5ODE2MTAsInJvbGUiOiJhY2NvdW50YW50In0.78VIR3X4QZohzeI5x3xmkmqcICTusOC6PELPohMV-k8",
|
|
||||||
"tokenType": "Bearer",
|
|
||||||
"expiresIn": 86400,
|
|
||||||
"userId": "96d2fd35-b39d-4c05-916a-66134453d34c",
|
|
||||||
"role": "accountant"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"username": "testuser4",
|
|
||||||
"email": "test4@example.com"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Register
|
|
||||||
{
|
|
||||||
"id": "413d7ecc-f231-48af-8c5a-566b1dc2bf0b",
|
|
||||||
"username": "testuser4",
|
|
||||||
"email": "test4@example.com",
|
|
||||||
"role": "accountant"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"identifier": "test4@example.com"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Login
|
|
||||||
{
|
|
||||||
"accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MTNkN2VjYy1mMjMxLTQ4YWYtOGM1YS01NjZiMWRjMmJmMGIiLCJleHAiOjE3NDI5ODE3MDEsInJvbGUiOiJhY2NvdW50YW50In0.4Hzu3tTZRNGHnBSgeCbGy2tFTl8EzpPdXBhcW8kuIc8",
|
|
||||||
"tokenType": "Bearer",
|
|
||||||
"expiresIn": 86400,
|
|
||||||
"userId": "413d7ecc-f231-48af-8c5a-566b1dc2bf0b",
|
|
||||||
"role": "accountant"
|
|
||||||
}
|
|
||||||
╭─ ~/Doc/pr/komp_ac/server auth ······ ✔
|
|
||||||
╰─
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"username": "testuser_default_role",
|
|
||||||
"email": "default@example.com",
|
|
||||||
"password": "password",
|
|
||||||
"password_confirmation": "password"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Register
|
|
||||||
{
|
|
||||||
"id": "73017288-af41-49d8-b4cb-2ac2109b38a1",
|
|
||||||
"username": "testuser_default_role",
|
|
||||||
"email": "default@example.com",
|
|
||||||
"role": "accountant"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"username": "testuser_admin_role",
|
|
||||||
"email": "admin@example.com",
|
|
||||||
"password": "password",
|
|
||||||
"password_confirmation": "password",
|
|
||||||
"role": "admin"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Register
|
|
||||||
{
|
|
||||||
"id": "9437e318-818b-4c34-822d-c2d6601b835e",
|
|
||||||
"username": "testuser_admin_role",
|
|
||||||
"email": "admin@example.com",
|
|
||||||
"role": "admin"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"username": "testuser_invalid_role",
|
|
||||||
"email": "invalid@example.com",
|
|
||||||
"password": "password",
|
|
||||||
"password_confirmation": "password",
|
|
||||||
"role": "invalid_role_name"
|
|
||||||
}' localhost:50051 komp_ac.auth.AuthService/Register
|
|
||||||
ERROR:
|
|
||||||
Code: InvalidArgument
|
|
||||||
Message: Invalid role specified: 'invalid_role_name'
|
|
||||||
╭─ ~/Doc/pr/komp_ac/server main +3 !1
|
|
||||||
╰─
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// src/auth/handlers.rs
|
|
||||||
|
|
||||||
pub mod register;
|
|
||||||
pub mod login;
|
|
||||||
|
|
||||||
pub use register::*;
|
|
||||||
pub use login::*;
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
// src/auth/handlers/login.rs
|
|
||||||
use bcrypt::verify;
|
|
||||||
use tonic::{Response, Status};
|
|
||||||
use crate::db::PgPool;
|
|
||||||
use crate::auth::logic::jwt; // Fixed import path
|
|
||||||
use common::proto::komp_ac::auth::{LoginRequest, LoginResponse};
|
|
||||||
|
|
||||||
pub async fn login(
|
|
||||||
pool: &PgPool,
|
|
||||||
request: LoginRequest,
|
|
||||||
) -> Result<Response<LoginResponse>, Status> {
|
|
||||||
let user = sqlx::query!(
|
|
||||||
r#"
|
|
||||||
SELECT id, username, password_hash, role
|
|
||||||
FROM users
|
|
||||||
WHERE username = $1 OR email = $1
|
|
||||||
"#,
|
|
||||||
request.identifier
|
|
||||||
)
|
|
||||||
.fetch_optional(pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?
|
|
||||||
.ok_or_else(|| Status::unauthenticated("Invalid credentials"))?;
|
|
||||||
|
|
||||||
// Handle the optional password_hash
|
|
||||||
let password_hash = user.password_hash
|
|
||||||
.ok_or_else(|| Status::internal("User account has no password set"))?;
|
|
||||||
|
|
||||||
// Verify the password
|
|
||||||
if !verify(&request.password, &password_hash)
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?
|
|
||||||
{
|
|
||||||
return Err(Status::unauthenticated("Invalid credentials"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let token = jwt::generate_token(user.id, &user.role, &user.username)
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?;
|
|
||||||
|
|
||||||
Ok(Response::new(LoginResponse {
|
|
||||||
access_token: token,
|
|
||||||
token_type: "Bearer".to_string(),
|
|
||||||
expires_in: 86400, // 24 hours
|
|
||||||
user_id: user.id.to_string(),
|
|
||||||
role: user.role,
|
|
||||||
username: user.username,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
// src/auth/handlers/register.rs
|
|
||||||
use bcrypt::{hash, DEFAULT_COST};
|
|
||||||
use tonic::{Response, Status};
|
|
||||||
use common::proto::komp_ac::auth::{RegisterRequest, AuthResponse};
|
|
||||||
use crate::db::PgPool;
|
|
||||||
use crate::auth::models::AuthError;
|
|
||||||
|
|
||||||
const DEFAULT_ROLE: &str = "accountant";
|
|
||||||
|
|
||||||
pub async fn register(
|
|
||||||
pool: &PgPool,
|
|
||||||
payload: RegisterRequest,
|
|
||||||
) -> Result<Response<AuthResponse>, Status> {
|
|
||||||
// Validate required fields
|
|
||||||
if payload.email.trim().is_empty() {
|
|
||||||
return Err(Status::invalid_argument("Email is required"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate passwords match
|
|
||||||
if payload.password != payload.password_confirmation {
|
|
||||||
return Err(Status::invalid_argument(AuthError::PasswordMismatch.to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash password
|
|
||||||
let password_hash = hash(payload.password, DEFAULT_COST)
|
|
||||||
.map_err(|e| Status::internal(AuthError::HashingError(e.to_string()).to_string()))?;
|
|
||||||
|
|
||||||
let role_to_insert = if payload.role.is_empty() { DEFAULT_ROLE } else { &payload.role };
|
|
||||||
|
|
||||||
// Insert user
|
|
||||||
let user = sqlx::query!(
|
|
||||||
r#"
|
|
||||||
INSERT INTO users (username, email, password_hash, role)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING id, username, email, role
|
|
||||||
"#,
|
|
||||||
payload.username,
|
|
||||||
payload.email,
|
|
||||||
password_hash,
|
|
||||||
role_to_insert
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
if let Some(db_err) = e.as_database_error() {
|
|
||||||
if db_err.constraint() == Some("valid_roles") {
|
|
||||||
return Status::invalid_argument(format!("Invalid role specified: '{}'", role_to_insert));
|
|
||||||
}
|
|
||||||
// Check for specific constraint violations
|
|
||||||
if let Some(constraint) = db_err.constraint() {
|
|
||||||
if constraint.contains("users_username_key") {
|
|
||||||
return Status::already_exists("Username already exists".to_string());
|
|
||||||
}
|
|
||||||
if constraint.contains("users_email_key") {
|
|
||||||
return Status::already_exists("Email already exists".to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if e.to_string().contains("duplicate key") {
|
|
||||||
Status::already_exists(AuthError::UserExists.to_string())
|
|
||||||
} else {
|
|
||||||
Status::internal(AuthError::DatabaseError(e.to_string()).to_string())
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(Response::new(AuthResponse {
|
|
||||||
id: user.id.to_string(),
|
|
||||||
username: user.username,
|
|
||||||
email: user.email.unwrap_or_default(),
|
|
||||||
role: user.role,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// src/auth/logic.rs
|
|
||||||
|
|
||||||
pub mod jwt;
|
|
||||||
pub mod middleware;
|
|
||||||
// TODO implement RBAC on all of the endpoints
|
|
||||||
// pub mod rbac;
|
|
||||||
|
|
||||||
pub use jwt::*;
|
|
||||||
pub use middleware::*;
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
// src/auth/jwt.rs
|
|
||||||
use jsonwebtoken::{encode, decode, Header, EncodingKey, DecodingKey, Validation};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use time::{Duration, OffsetDateTime};
|
|
||||||
use uuid::Uuid;
|
|
||||||
use std::sync::OnceLock;
|
|
||||||
use crate::auth::models::AuthError;
|
|
||||||
|
|
||||||
static KEYS: OnceLock<Keys> = OnceLock::new();
|
|
||||||
|
|
||||||
struct Keys {
|
|
||||||
encoding: EncodingKey,
|
|
||||||
decoding: DecodingKey,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
pub struct Claims {
|
|
||||||
pub sub: Uuid, // User ID
|
|
||||||
pub exp: i64, // Expiration time
|
|
||||||
pub role: String, // User role
|
|
||||||
pub username: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_jwt() -> Result<(), AuthError> {
|
|
||||||
let secret = std::env::var("JWT_SECRET")
|
|
||||||
.map_err(|_| AuthError::ConfigError("JWT_SECRET must be set".to_string()))?;
|
|
||||||
|
|
||||||
KEYS.set(Keys {
|
|
||||||
encoding: EncodingKey::from_secret(secret.as_bytes()),
|
|
||||||
decoding: DecodingKey::from_secret(secret.as_bytes()),
|
|
||||||
}).map_err(|_| AuthError::ConfigError("Failed to initialize JWT keys".to_string()))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate_token(user_id: Uuid, role: &str, username: &str) -> Result<String, AuthError> {
|
|
||||||
let keys = KEYS.get().ok_or(AuthError::ConfigError("JWT not initialized".to_string()))?;
|
|
||||||
|
|
||||||
let exp = OffsetDateTime::now_utc() + Duration::days(365000);
|
|
||||||
let claims = Claims {
|
|
||||||
sub: user_id,
|
|
||||||
exp: exp.unix_timestamp(),
|
|
||||||
role: role.to_string(),
|
|
||||||
username: username.to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
encode(&Header::default(), &claims, &keys.encoding)
|
|
||||||
.map_err(|e| AuthError::JwtError(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn validate_token(token: &str) -> Result<Claims, AuthError> {
|
|
||||||
let keys = KEYS.get().ok_or(AuthError::ConfigError("JWT not initialized".to_string()))?;
|
|
||||||
|
|
||||||
decode::<Claims>(token, &keys.decoding, &Validation::default())
|
|
||||||
.map(|data| data.claims)
|
|
||||||
.map_err(|e| AuthError::JwtError(e.to_string()))
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
// src/auth/middleware.rs
|
|
||||||
use tonic::{service::Interceptor, Status};
|
|
||||||
use crate::auth::logic::jwt;
|
|
||||||
|
|
||||||
pub struct AuthInterceptor;
|
|
||||||
|
|
||||||
impl Interceptor for AuthInterceptor {
|
|
||||||
fn call(&mut self, mut request: tonic::Request<()>) -> Result<tonic::Request<()>, Status> {
|
|
||||||
let metadata = request.metadata();
|
|
||||||
let token = metadata.get("authorization")
|
|
||||||
.and_then(|v| v.to_str().ok())
|
|
||||||
.and_then(|s| s.strip_prefix("Bearer "))
|
|
||||||
.ok_or(Status::unauthenticated("Missing authorization header"))?;
|
|
||||||
|
|
||||||
let claims = jwt::validate_token(token)
|
|
||||||
.map_err(|e| Status::unauthenticated(e.to_string()))?;
|
|
||||||
|
|
||||||
// Store claims in request extensions
|
|
||||||
request.extensions_mut().insert(claims);
|
|
||||||
Ok(request)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
// src/auth/logic/rbac.rs
|
|
||||||
|
|
||||||
use tower::ServiceBuilder;
|
|
||||||
use crate::auth::logic::rbac;
|
|
||||||
|
|
||||||
// TODO redesign this, adresar and uctovnictvo are nonexistent, but we are keeping this code for
|
|
||||||
// the reference. Please adjust in the future rbac.
|
|
||||||
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
// ... existing setup code ...
|
|
||||||
|
|
||||||
// Create service layers
|
|
||||||
let adresar_layer = ServiceBuilder::new()
|
|
||||||
.layer(rbac::create_adresar_layer())
|
|
||||||
.into_inner();
|
|
||||||
|
|
||||||
let uctovnictvo_layer = ServiceBuilder::new()
|
|
||||||
.layer(rbac::create_uctovnictvo_layer())
|
|
||||||
.into_inner();
|
|
||||||
|
|
||||||
// Create services with layers
|
|
||||||
let adresar_service = AdresarServer::new(AdresarService { db_pool: db_pool.clone() })
|
|
||||||
.layer(adresar_layer);
|
|
||||||
|
|
||||||
let uctovnictvo_service = UctovnictvoServer::new(UctovnictvoService { db_pool: db_pool.clone() })
|
|
||||||
.layer(uctovnictvo_layer);
|
|
||||||
|
|
||||||
// ... repeat for other services ...
|
|
||||||
|
|
||||||
Server::builder()
|
|
||||||
.add_service(auth_server)
|
|
||||||
.add_service(adresar_service)
|
|
||||||
.add_service(uctovnictvo_service)
|
|
||||||
// ... other services ...
|
|
||||||
.serve(addr)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// src/auth/mod.rs
|
|
||||||
|
|
||||||
pub mod models;
|
|
||||||
pub mod logic;
|
|
||||||
pub mod handlers;
|
|
||||||
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
// src/auth/models.rs
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Debug, Validate, Deserialize)]
|
|
||||||
pub struct RegisterRequest {
|
|
||||||
#[validate(length(min = 1, max = 30))]
|
|
||||||
pub username: String,
|
|
||||||
#[validate(email)]
|
|
||||||
pub email: String,
|
|
||||||
#[validate(length(min = 1))]
|
|
||||||
pub password: String,
|
|
||||||
pub password_confirmation: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Validate, Deserialize)]
|
|
||||||
pub struct LoginRequest {
|
|
||||||
#[validate(length(min = 1))]
|
|
||||||
pub identifier: String,
|
|
||||||
#[validate(length(min = 1))]
|
|
||||||
pub password: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum AuthError {
|
|
||||||
#[error("Passwords do not match")]
|
|
||||||
PasswordMismatch,
|
|
||||||
#[error("User already exists")]
|
|
||||||
UserExists,
|
|
||||||
#[error("Database error: {0}")]
|
|
||||||
DatabaseError(String),
|
|
||||||
#[error("Hashing error: {0}")]
|
|
||||||
HashingError(String),
|
|
||||||
#[error("Invalid credentials")]
|
|
||||||
InvalidCredentials,
|
|
||||||
#[error("JWT error: {0}")]
|
|
||||||
JwtError(String),
|
|
||||||
#[error("Configuration error: {0}")]
|
|
||||||
ConfigError(String),
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
// src/db.rs
|
|
||||||
|
|
||||||
use sqlx::postgres::PgPoolOptions;
|
|
||||||
pub use sqlx::postgres::PgPool;
|
|
||||||
use std::time::Duration;
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct DatabaseConfig {
|
|
||||||
pub username: String,
|
|
||||||
pub password: String,
|
|
||||||
pub host: String,
|
|
||||||
pub port: u16,
|
|
||||||
pub database_name: String,
|
|
||||||
pub max_connections: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DatabaseConfig {
|
|
||||||
pub fn from_env() -> Self {
|
|
||||||
Self {
|
|
||||||
username: std::env::var("RUST_DB_USER").expect("RUST_DB_USER must be set"),
|
|
||||||
password: std::env::var("RUST_DB_PASSWORD").expect("RUST_DB_PASSWORD must be set"),
|
|
||||||
host: std::env::var("RUST_DB_HOST").expect("RUST_DB_HOST must be set"),
|
|
||||||
port: std::env::var("RUST_DB_PORT")
|
|
||||||
.expect("RUST_DB_PORT must be set")
|
|
||||||
.parse()
|
|
||||||
.expect("RUST_DB_PORT must be a valid port number"),
|
|
||||||
database_name: std::env::var("RUST_DB_NAME").expect("RUST_DB_NAME must be set"),
|
|
||||||
max_connections: 5,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn connection_string(&self) -> String {
|
|
||||||
format!(
|
|
||||||
"postgres://{}:{}@{}:{}/{}",
|
|
||||||
self.username, self.password, self.host, self.port, self.database_name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create_pool(config: &DatabaseConfig) -> Result<PgPool, sqlx::Error> {
|
|
||||||
let conn_str = config.connection_string();
|
|
||||||
info!("Connecting to database: {}", conn_str);
|
|
||||||
PgPoolOptions::new()
|
|
||||||
.max_connections(config.max_connections)
|
|
||||||
.acquire_timeout(Duration::from_secs(3))
|
|
||||||
.connect(&conn_str)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn check_connection(pool: &PgPool) -> Result<(), sqlx::Error> {
|
|
||||||
sqlx::query("SELECT 1").execute(pool).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
// server/src/indexer.rs
|
|
||||||
|
|
||||||
use sqlx::{PgPool, Row};
|
|
||||||
use tantivy::schema::Term;
|
|
||||||
use tantivy::{doc, IndexWriter};
|
|
||||||
use tokio::sync::mpsc::Receiver;
|
|
||||||
use tracing::{error, info, warn};
|
|
||||||
use tantivy::schema::Schema;
|
|
||||||
use crate::search_schema;
|
|
||||||
|
|
||||||
/// Defines the commands that can be sent to the indexer task.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum IndexCommand {
|
|
||||||
/// Add a new document or update an existing one.
|
|
||||||
AddOrUpdate(IndexCommandData),
|
|
||||||
/// Remove a document from the index.
|
|
||||||
Delete(IndexCommandData),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct IndexCommandData {
|
|
||||||
pub table_name: String,
|
|
||||||
pub row_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The main loop for the background indexer task.
|
|
||||||
pub async fn indexer_task(pool: PgPool, mut receiver: Receiver<IndexCommand>) {
|
|
||||||
info!("Background indexer task started.");
|
|
||||||
while let Some(command) = receiver.recv().await {
|
|
||||||
info!("Indexer received command: {:?}", command);
|
|
||||||
let result = match command {
|
|
||||||
IndexCommand::AddOrUpdate(data) => {
|
|
||||||
handle_add_or_update(&pool, data).await
|
|
||||||
}
|
|
||||||
IndexCommand::Delete(data) => handle_delete(&pool, data).await,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(e) = result {
|
|
||||||
error!("Failed to process index command: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
warn!("Indexer channel closed. Task is shutting down.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles adding or updating a document in a Tantivy index.
|
|
||||||
async fn handle_add_or_update(
|
|
||||||
pool: &PgPool,
|
|
||||||
data: IndexCommandData,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
let qualified_table = format!("gen.\"{}\"", data.table_name);
|
|
||||||
let query_str = format!(
|
|
||||||
"SELECT to_jsonb(t) AS data FROM {} t WHERE id = $1",
|
|
||||||
qualified_table
|
|
||||||
);
|
|
||||||
let row = sqlx::query(&query_str)
|
|
||||||
.bind(data.row_id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
let json_data: serde_json::Value = row.try_get("data")?;
|
|
||||||
let slovak_text = extract_text_content(&json_data);
|
|
||||||
|
|
||||||
let (mut writer, schema) = get_index_writer(&data.table_name)?;
|
|
||||||
let pg_id_field = schema.get_field("pg_id").unwrap();
|
|
||||||
let prefix_edge_field = schema.get_field("prefix_edge").unwrap();
|
|
||||||
let prefix_full_field = schema.get_field("prefix_full").unwrap();
|
|
||||||
let text_ngram_field = schema.get_field("text_ngram").unwrap();
|
|
||||||
|
|
||||||
let id_term = Term::from_field_u64(pg_id_field, data.row_id as u64);
|
|
||||||
writer.delete_term(id_term);
|
|
||||||
|
|
||||||
writer.add_document(doc!(
|
|
||||||
pg_id_field => data.row_id as u64,
|
|
||||||
prefix_edge_field => slovak_text.clone(),
|
|
||||||
prefix_full_field => slovak_text.clone(),
|
|
||||||
text_ngram_field => slovak_text
|
|
||||||
))?;
|
|
||||||
|
|
||||||
writer.commit()?;
|
|
||||||
info!(
|
|
||||||
"Successfully indexed document id:{} for table:{}",
|
|
||||||
data.row_id, data.table_name
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles deleting a document from a Tantivy index.
|
|
||||||
async fn handle_delete(
|
|
||||||
_pool: &PgPool,
|
|
||||||
data: IndexCommandData,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
let (mut writer, schema) = get_index_writer(&data.table_name)?;
|
|
||||||
let pg_id_field = schema.get_field("pg_id").unwrap();
|
|
||||||
|
|
||||||
let id_term = Term::from_field_u64(pg_id_field, data.row_id as u64);
|
|
||||||
writer.delete_term(id_term);
|
|
||||||
writer.commit()?;
|
|
||||||
|
|
||||||
info!(
|
|
||||||
"Successfully deleted document id:{} from table:{}",
|
|
||||||
data.row_id, data.table_name
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper to get or create an index and return its writer and schema.
|
|
||||||
fn get_index_writer(
|
|
||||||
table_name: &str,
|
|
||||||
) -> anyhow::Result<(IndexWriter, Schema)> {
|
|
||||||
let index = search_schema::get_or_create_index(table_name)?;
|
|
||||||
let schema = index.schema();
|
|
||||||
let writer = index.writer(100_000_000)?; // 100MB heap
|
|
||||||
Ok((writer, schema))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extract all text content from a JSON object for indexing
|
|
||||||
fn extract_text_content(json_data: &serde_json::Value) -> String {
|
|
||||||
let mut full_text = String::new();
|
|
||||||
|
|
||||||
if let Some(obj) = json_data.as_object() {
|
|
||||||
for value in obj.values() {
|
|
||||||
match value {
|
|
||||||
serde_json::Value::String(s) => {
|
|
||||||
full_text.push_str(s);
|
|
||||||
full_text.push(' ');
|
|
||||||
}
|
|
||||||
serde_json::Value::Number(n) => {
|
|
||||||
full_text.push_str(&n.to_string());
|
|
||||||
full_text.push(' ');
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
full_text.trim().to_string()
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// src/lib.rs
|
|
||||||
pub mod db;
|
|
||||||
pub mod auth;
|
|
||||||
pub mod indexer;
|
|
||||||
pub mod search_schema;
|
|
||||||
pub mod server;
|
|
||||||
pub mod shared;
|
|
||||||
pub mod table_structure;
|
|
||||||
pub mod table_definition;
|
|
||||||
pub mod tables_data;
|
|
||||||
pub mod table_script;
|
|
||||||
pub mod steel;
|
|
||||||
pub mod table_validation;
|
|
||||||
|
|
||||||
// Re-export run_server from the inner server module:
|
|
||||||
pub use server::run_server;
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
// server/src/main.rs
|
|
||||||
use std::env;
|
|
||||||
use dotenvy::dotenv;
|
|
||||||
|
|
||||||
// Import from the external library crate (named `server`)
|
|
||||||
use server::run_server;
|
|
||||||
use server::db;
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
dotenv().ok();
|
|
||||||
|
|
||||||
// Initialize database using library module `db`
|
|
||||||
let db_config = db::DatabaseConfig::from_env();
|
|
||||||
let db_pool = db::create_pool(&db_config).await?;
|
|
||||||
|
|
||||||
match env::args().nth(1).as_deref() {
|
|
||||||
Some("server") => run_server(db_pool).await?,
|
|
||||||
_ => println!("Usage: cargo run -- [server|client]"),
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
// server/src/search_schema.rs
|
|
||||||
|
|
||||||
use std::path::Path;
|
|
||||||
use tantivy::Index;
|
|
||||||
|
|
||||||
// Re-export the functions from the common crate.
|
|
||||||
// This makes them available as `crate::search_schema::create_search_schema`, etc.
|
|
||||||
pub use common::search::{create_search_schema, register_slovak_tokenizers};
|
|
||||||
|
|
||||||
/// Gets an existing index or creates a new one.
|
|
||||||
/// This function now uses the shared logic from the `common` crate.
|
|
||||||
pub fn get_or_create_index(table_name: &str) -> tantivy::Result<Index> {
|
|
||||||
let index_path = Path::new("./tantivy_indexes").join(table_name);
|
|
||||||
std::fs::create_dir_all(&index_path)?;
|
|
||||||
|
|
||||||
let index = if index_path.join("meta.json").exists() {
|
|
||||||
Index::open_in_dir(&index_path)?
|
|
||||||
} else {
|
|
||||||
let schema = create_search_schema();
|
|
||||||
Index::create_in_dir(&index_path, schema)?
|
|
||||||
};
|
|
||||||
|
|
||||||
// This now calls the single, authoritative function from `common`.
|
|
||||||
register_slovak_tokenizers(&index)?;
|
|
||||||
Ok(index)
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// src/server/handlers.rs
|
|
||||||
pub use crate::server::services::table_structure_service::TableStructureHandler;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// src/server/mod.rs
|
|
||||||
pub mod services;
|
|
||||||
pub mod handlers;
|
|
||||||
pub mod run;
|
|
||||||
|
|
||||||
pub use run::run_server;
|
|
||||||
pub use services::*;
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
use tonic::transport::Server;
|
|
||||||
use tonic_reflection::server::Builder as ReflectionBuilder;
|
|
||||||
|
|
||||||
use tokio::sync::mpsc;
|
|
||||||
use crate::indexer::{indexer_task, IndexCommand};
|
|
||||||
|
|
||||||
use common::proto::komp_ac::FILE_DESCRIPTOR_SET;
|
|
||||||
use crate::server::services::{
|
|
||||||
TableStructureHandler,
|
|
||||||
TableDefinitionService,
|
|
||||||
TablesDataService,
|
|
||||||
TableScriptService,
|
|
||||||
AuthServiceImpl,
|
|
||||||
Search2Service,
|
|
||||||
};
|
|
||||||
use common::proto::komp_ac::{
|
|
||||||
table_structure::table_structure_service_server::TableStructureServiceServer,
|
|
||||||
table_definition::table_definition_server::TableDefinitionServer,
|
|
||||||
table_validation::table_validation_service_server::TableValidationServiceServer,
|
|
||||||
tables_data::tables_data_server::TablesDataServer,
|
|
||||||
table_script::table_script_server::TableScriptServer,
|
|
||||||
auth::auth_service_server::AuthServiceServer,
|
|
||||||
search2::search2_server::Search2Server,
|
|
||||||
};
|
|
||||||
use search::{SearcherService, SearcherServer};
|
|
||||||
use crate::table_validation::get::service::TableValidationSvc;
|
|
||||||
|
|
||||||
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
// Initialize JWT for authentication
|
|
||||||
crate::auth::logic::jwt::init_jwt()?;
|
|
||||||
|
|
||||||
let addr = "[::1]:50051".parse()?;
|
|
||||||
println!("Unified Server listening on {}", addr);
|
|
||||||
|
|
||||||
// 1. Create the MPSC channel for indexer commands
|
|
||||||
let (indexer_tx, indexer_rx) = mpsc::channel::<IndexCommand>(100); // Buffer of 100 messages
|
|
||||||
|
|
||||||
// 2. Spawn the background indexer task
|
|
||||||
let indexer_pool = db_pool.clone();
|
|
||||||
tokio::spawn(indexer_task(indexer_pool, indexer_rx));
|
|
||||||
|
|
||||||
let reflection_service = ReflectionBuilder::configure()
|
|
||||||
.register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET)
|
|
||||||
.build_v1()?;
|
|
||||||
|
|
||||||
// Initialize services, passing the indexer sender to the relevant ones
|
|
||||||
let table_definition_service = TableDefinitionService { db_pool: db_pool.clone() };
|
|
||||||
let table_validation_service = TableValidationSvc { db: db_pool.clone() };
|
|
||||||
let tables_data_service = TablesDataService {
|
|
||||||
db_pool: db_pool.clone(),
|
|
||||||
indexer_tx: indexer_tx.clone(),
|
|
||||||
};
|
|
||||||
let table_script_service = TableScriptService { db_pool: db_pool.clone() };
|
|
||||||
let auth_service = AuthServiceImpl { db_pool: db_pool.clone() };
|
|
||||||
let search_service = SearcherService { pool: db_pool.clone() };
|
|
||||||
let search2_service = Search2Service { db_pool: db_pool.clone() };
|
|
||||||
|
|
||||||
Server::builder()
|
|
||||||
.add_service(TableStructureServiceServer::new(TableStructureHandler { db_pool: db_pool.clone() }))
|
|
||||||
.add_service(TableDefinitionServer::new(table_definition_service))
|
|
||||||
.add_service(TableValidationServiceServer::new(table_validation_service))
|
|
||||||
.add_service(TablesDataServer::new(tables_data_service))
|
|
||||||
.add_service(TableScriptServer::new(table_script_service))
|
|
||||||
.add_service(AuthServiceServer::new(auth_service))
|
|
||||||
.add_service(SearcherServer::new(search_service))
|
|
||||||
.add_service(Search2Server::new(search2_service))
|
|
||||||
.add_service(reflection_service)
|
|
||||||
.serve(addr)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
// src/server/services/auth_service.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
use common::proto::komp_ac::auth::{
|
|
||||||
auth_service_server::AuthService,
|
|
||||||
RegisterRequest, AuthResponse,
|
|
||||||
LoginRequest, LoginResponse
|
|
||||||
};
|
|
||||||
use crate::auth::handlers::{
|
|
||||||
login::login,
|
|
||||||
register::register
|
|
||||||
};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AuthServiceImpl {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl AuthService for AuthServiceImpl {
|
|
||||||
async fn register(
|
|
||||||
&self,
|
|
||||||
request: Request<RegisterRequest>,
|
|
||||||
) -> Result<Response<AuthResponse>, Status> {
|
|
||||||
let response = register(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn login(
|
|
||||||
&self,
|
|
||||||
request: Request<LoginRequest>,
|
|
||||||
) -> Result<Response<LoginResponse>, Status> {
|
|
||||||
let response = login(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// src/server/services/mod.rs
|
|
||||||
|
|
||||||
pub mod table_structure_service;
|
|
||||||
pub mod table_definition_service;
|
|
||||||
pub mod table_validation_service;
|
|
||||||
pub mod tables_data_service;
|
|
||||||
pub mod table_script_service;
|
|
||||||
pub mod auth_service;
|
|
||||||
pub mod search2_service;
|
|
||||||
|
|
||||||
pub use table_structure_service::TableStructureHandler;
|
|
||||||
pub use table_definition_service::TableDefinitionService;
|
|
||||||
pub use table_validation_service::*;
|
|
||||||
pub use tables_data_service::TablesDataService;
|
|
||||||
pub use table_script_service::TableScriptService;
|
|
||||||
pub use auth_service::AuthServiceImpl;
|
|
||||||
pub use search2_service::*;
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
// src/server/services/search2_service.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use sqlx::Row;
|
|
||||||
use common::proto::komp_ac::search2::{
|
|
||||||
search2_server::Search2,
|
|
||||||
Search2Request, Search2Response, ColumnFilter, FilterType,
|
|
||||||
search2_response::Hit,
|
|
||||||
};
|
|
||||||
use crate::shared::schema_qualifier::qualify_table_name_for_data;
|
|
||||||
|
|
||||||
pub struct Search2Service {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl Search2 for Search2Service {
|
|
||||||
async fn search_table(
|
|
||||||
&self,
|
|
||||||
request: Request<Search2Request>,
|
|
||||||
) -> Result<Response<Search2Response>, Status> {
|
|
||||||
let req = request.into_inner();
|
|
||||||
|
|
||||||
// Build SQL query - NOW PASS DB_POOL AND AWAIT
|
|
||||||
let (sql, bind_values, count_sql) = build_search_query(&self.db_pool, &req).await
|
|
||||||
.map_err(|e| Status::invalid_argument(format!("Query build error: {}", e)))?;
|
|
||||||
|
|
||||||
// Execute main query
|
|
||||||
let rows = execute_query(&self.db_pool, &sql, &bind_values).await
|
|
||||||
.map_err(|e| Status::internal(format!("Database error: {}", e)))?;
|
|
||||||
|
|
||||||
// Execute count query for pagination
|
|
||||||
let total_count = execute_count_query(&self.db_pool, &count_sql, &bind_values).await
|
|
||||||
.map_err(|e| Status::internal(format!("Count query error: {}", e)))?;
|
|
||||||
|
|
||||||
// Convert to response format
|
|
||||||
let hits = rows.into_iter().map(|row| {
|
|
||||||
Hit {
|
|
||||||
id: row.id,
|
|
||||||
content_json: row.content_json,
|
|
||||||
match_info: Some(format!("SQL search on table: {}", req.table_name)),
|
|
||||||
}
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
Ok(Response::new(Search2Response {
|
|
||||||
hits,
|
|
||||||
total_count,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct QueryRow {
|
|
||||||
id: i64,
|
|
||||||
content_json: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
// MAKE THIS FUNCTION ASYNC AND ADD DB_POOL PARAMETER
|
|
||||||
async fn build_search_query(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: &Search2Request
|
|
||||||
) -> Result<(String, Vec<String>, String), String> {
|
|
||||||
|
|
||||||
// Since Search2Request doesn't have profile_name, use "default"
|
|
||||||
// You can add profile_name to the proto later if needed
|
|
||||||
let profile_name = "default";
|
|
||||||
|
|
||||||
// NOW AWAIT THE ASYNC FUNCTION CALL
|
|
||||||
let qualified_table = qualify_table_name_for_data(db_pool, profile_name, &request.table_name)
|
|
||||||
.await
|
|
||||||
.map_err(|e| format!("Invalid table name: {}", e))?;
|
|
||||||
|
|
||||||
let mut conditions = vec!["deleted = FALSE".to_string()];
|
|
||||||
let mut bind_values = Vec::new();
|
|
||||||
|
|
||||||
// Build WHERE conditions from column filters
|
|
||||||
for filter in &request.column_filters {
|
|
||||||
let condition = build_filter_condition(filter, &mut bind_values)?;
|
|
||||||
conditions.push(condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add text search fallback if provided
|
|
||||||
if let Some(text_query) = &request.text_query {
|
|
||||||
if !text_query.trim().is_empty() {
|
|
||||||
bind_values.push(format!("%{}%", text_query.to_lowercase()));
|
|
||||||
conditions.push(format!(
|
|
||||||
"EXISTS (SELECT 1 FROM jsonb_each_text(to_jsonb(t)) as kv(key, value) WHERE LOWER(value) LIKE ${})",
|
|
||||||
bind_values.len()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let where_clause = conditions.join(" AND ");
|
|
||||||
|
|
||||||
// Build ORDER BY clause
|
|
||||||
let order_clause = if let Some(order_by) = &request.order_by {
|
|
||||||
let direction = if request.order_desc.unwrap_or(false) { "DESC" } else { "ASC" };
|
|
||||||
format!("ORDER BY \"{}\" {}", order_by, direction)
|
|
||||||
} else {
|
|
||||||
"ORDER BY id DESC".to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
let limit_clause = format!("LIMIT {}", request.limit.unwrap_or(100));
|
|
||||||
|
|
||||||
// Main query
|
|
||||||
let sql = format!(
|
|
||||||
"SELECT id, to_jsonb(t) AS data FROM {} t WHERE {} {} {}",
|
|
||||||
qualified_table, where_clause, order_clause, limit_clause
|
|
||||||
);
|
|
||||||
|
|
||||||
// Count query (for pagination)
|
|
||||||
let count_sql = format!(
|
|
||||||
"SELECT COUNT(*) FROM {} t WHERE {}",
|
|
||||||
qualified_table, where_clause
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok((sql, bind_values, count_sql))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_filter_condition(filter: &ColumnFilter, bind_values: &mut Vec<String>) -> Result<String, String> {
|
|
||||||
// FIX DEPRECATED WARNING - USE TryFrom INSTEAD
|
|
||||||
let filter_type = FilterType::try_from(filter.filter_type)
|
|
||||||
.map_err(|_| "Invalid filter type".to_string())?;
|
|
||||||
|
|
||||||
let param_idx = bind_values.len() + 1;
|
|
||||||
|
|
||||||
let condition = match filter_type {
|
|
||||||
FilterType::Equals => {
|
|
||||||
bind_values.push(filter.value.clone());
|
|
||||||
format!("\"{}\" = ${}", filter.column_name, param_idx)
|
|
||||||
},
|
|
||||||
FilterType::Contains => {
|
|
||||||
bind_values.push(format!("%{}%", filter.value));
|
|
||||||
format!("\"{}\" ILIKE ${}", filter.column_name, param_idx)
|
|
||||||
},
|
|
||||||
FilterType::StartsWith => {
|
|
||||||
bind_values.push(format!("{}%", filter.value));
|
|
||||||
format!("\"{}\" ILIKE ${}", filter.column_name, param_idx)
|
|
||||||
},
|
|
||||||
FilterType::EndsWith => {
|
|
||||||
bind_values.push(format!("%{}", filter.value));
|
|
||||||
format!("\"{}\" ILIKE ${}", filter.column_name, param_idx)
|
|
||||||
},
|
|
||||||
FilterType::Range => {
|
|
||||||
bind_values.push(filter.value.clone());
|
|
||||||
bind_values.push(filter.value2.as_ref().unwrap_or(&"".to_string()).clone());
|
|
||||||
format!("\"{}\" BETWEEN ${} AND ${}", filter.column_name, param_idx, param_idx + 1)
|
|
||||||
},
|
|
||||||
FilterType::GreaterThan => {
|
|
||||||
bind_values.push(filter.value.clone());
|
|
||||||
format!("\"{}\" > ${}", filter.column_name, param_idx)
|
|
||||||
},
|
|
||||||
FilterType::LessThan => {
|
|
||||||
bind_values.push(filter.value.clone());
|
|
||||||
format!("\"{}\" < ${}", filter.column_name, param_idx)
|
|
||||||
},
|
|
||||||
FilterType::IsNull => {
|
|
||||||
format!("\"{}\" IS NULL", filter.column_name)
|
|
||||||
},
|
|
||||||
FilterType::IsNotNull => {
|
|
||||||
format!("\"{}\" IS NOT NULL", filter.column_name)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(condition)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_query(pool: &PgPool, sql: &str, bind_values: &[String]) -> Result<Vec<QueryRow>, sqlx::Error> {
|
|
||||||
let mut query = sqlx::query(sql);
|
|
||||||
|
|
||||||
// Bind all parameters
|
|
||||||
for value in bind_values {
|
|
||||||
query = query.bind(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
let rows = query.fetch_all(pool).await?;
|
|
||||||
|
|
||||||
let results = rows.into_iter().map(|row| {
|
|
||||||
QueryRow {
|
|
||||||
id: row.try_get("id").unwrap_or(0),
|
|
||||||
content_json: row.try_get::<serde_json::Value, _>("data")
|
|
||||||
.unwrap_or(serde_json::Value::Null)
|
|
||||||
.to_string(),
|
|
||||||
}
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
Ok(results)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_count_query(pool: &PgPool, sql: &str, bind_values: &[String]) -> Result<i32, sqlx::Error> {
|
|
||||||
let mut query = sqlx::query(sql);
|
|
||||||
|
|
||||||
// Bind all parameters
|
|
||||||
for value in bind_values {
|
|
||||||
query = query.bind(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
let row = query.fetch_one(pool).await?;
|
|
||||||
let count: i64 = row.try_get(0).unwrap_or(0);
|
|
||||||
|
|
||||||
Ok(count as i32)
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
// src/server/services/table_definition_service.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
use common::proto::komp_ac::{
|
|
||||||
common::Empty,
|
|
||||||
table_definition::{
|
|
||||||
table_definition_server::TableDefinition,
|
|
||||||
PostTableDefinitionRequest, TableDefinitionResponse,
|
|
||||||
ProfileTreeResponse, DeleteTableRequest, DeleteTableResponse,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use crate::table_definition::handlers::{post_table_definition, get_profile_tree, delete_table};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TableDefinitionService {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableDefinitionService {
|
|
||||||
pub fn new(db_pool: PgPool) -> Self {
|
|
||||||
Self { db_pool }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl TableDefinition for TableDefinitionService {
|
|
||||||
async fn post_table_definition(
|
|
||||||
&self,
|
|
||||||
request: Request<PostTableDefinitionRequest>,
|
|
||||||
) -> Result<Response<TableDefinitionResponse>, Status> {
|
|
||||||
let response = post_table_definition(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_profile_tree(
|
|
||||||
&self,
|
|
||||||
request: Request<Empty>,
|
|
||||||
) -> Result<Response<ProfileTreeResponse>, Status> {
|
|
||||||
get_profile_tree::get_profile_tree(&self.db_pool, request).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_table(
|
|
||||||
&self,
|
|
||||||
request: Request<DeleteTableRequest>,
|
|
||||||
) -> Result<Response<DeleteTableResponse>, Status> {
|
|
||||||
let response = delete_table(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// src/server/services/table_script_service.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
use common::proto::komp_ac::table_script::{
|
|
||||||
table_script_server::TableScript,
|
|
||||||
PostTableScriptRequest, TableScriptResponse
|
|
||||||
};
|
|
||||||
use crate::table_script::handlers::post_table_script;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TableScriptService {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl TableScript for TableScriptService {
|
|
||||||
async fn post_table_script(
|
|
||||||
&self,
|
|
||||||
request: Request<PostTableScriptRequest>,
|
|
||||||
) -> Result<Response<TableScriptResponse>, Status> {
|
|
||||||
let request = request.into_inner();
|
|
||||||
let response = post_table_script(&self.db_pool, request).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// src/server/services/table_structure_service.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
// Correct the import path for the TableStructureService trait
|
|
||||||
use common::proto::komp_ac::table_structure::table_structure_service_server::TableStructureService;
|
|
||||||
use common::proto::komp_ac::table_structure::{
|
|
||||||
GetTableStructureRequest,
|
|
||||||
TableStructureResponse,
|
|
||||||
};
|
|
||||||
use crate::table_structure::handlers::get_table_structure;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TableStructureHandler {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableStructureHandler {
|
|
||||||
pub fn new(db_pool: PgPool) -> Self {
|
|
||||||
Self { db_pool }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl TableStructureService for TableStructureHandler { // This line should now be correct
|
|
||||||
async fn get_table_structure(
|
|
||||||
&self,
|
|
||||||
request: Request<GetTableStructureRequest>,
|
|
||||||
) -> Result<Response<TableStructureResponse>, Status> {
|
|
||||||
let req_payload = request.into_inner();
|
|
||||||
let response =
|
|
||||||
get_table_structure(&self.db_pool, req_payload).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// src/server/services/table_validation_service.rs
|
|
||||||
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
use common::proto::komp_ac::table_validation::table_validation_service_server::TableValidationServiceServer;
|
|
||||||
use crate::table_validation::get::service::TableValidationSvc;
|
|
||||||
|
|
||||||
pub fn svc(db: PgPool) -> TableValidationServiceServer<TableValidationSvc> {
|
|
||||||
TableValidationServiceServer::new(TableValidationSvc { db })
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
// src/server/services/tables_data_service.rs
|
|
||||||
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
// Add these imports
|
|
||||||
use tokio::sync::mpsc;
|
|
||||||
use crate::indexer::IndexCommand;
|
|
||||||
|
|
||||||
use common::proto::komp_ac::tables_data::tables_data_server::TablesData;
|
|
||||||
use common::proto::komp_ac::common::CountResponse;
|
|
||||||
use common::proto::komp_ac::tables_data::{
|
|
||||||
PostTableDataRequest, PostTableDataResponse,
|
|
||||||
PutTableDataRequest, PutTableDataResponse,
|
|
||||||
DeleteTableDataRequest, DeleteTableDataResponse,
|
|
||||||
GetTableDataRequest, GetTableDataResponse,
|
|
||||||
GetTableDataCountRequest, GetTableDataByPositionRequest,
|
|
||||||
};
|
|
||||||
use crate::tables_data::handlers::{post_table_data, put_table_data, delete_table_data, get_table_data, get_table_data_count, get_table_data_by_position};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TablesDataService {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
// MODIFIED: Add the sender field
|
|
||||||
pub indexer_tx: mpsc::Sender<IndexCommand>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl TablesData for TablesDataService {
|
|
||||||
async fn post_table_data(
|
|
||||||
&self,
|
|
||||||
request: Request<PostTableDataRequest>,
|
|
||||||
) -> Result<Response<PostTableDataResponse>, Status> {
|
|
||||||
let request = request.into_inner();
|
|
||||||
// MODIFIED: Pass the indexer_tx to the handler
|
|
||||||
let response = post_table_data(
|
|
||||||
&self.db_pool,
|
|
||||||
request,
|
|
||||||
&self.indexer_tx,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn put_table_data(
|
|
||||||
&self,
|
|
||||||
request: Request<PutTableDataRequest>,
|
|
||||||
) -> Result<Response<PutTableDataResponse>, Status> {
|
|
||||||
let request = request.into_inner();
|
|
||||||
let response = put_table_data(
|
|
||||||
&self.db_pool,
|
|
||||||
request,
|
|
||||||
&self.indexer_tx,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ...and delete_table_data
|
|
||||||
async fn delete_table_data(
|
|
||||||
&self,
|
|
||||||
request: Request<DeleteTableDataRequest>,
|
|
||||||
) -> Result<Response<DeleteTableDataResponse>, Status> {
|
|
||||||
let request = request.into_inner();
|
|
||||||
// TODO: Update delete_table_data handler to accept and use indexer_tx
|
|
||||||
let response = delete_table_data(&self.db_pool, request).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_table_data(
|
|
||||||
&self,
|
|
||||||
request: Request<GetTableDataRequest>,
|
|
||||||
) -> Result<Response<GetTableDataResponse>, Status> {
|
|
||||||
let request = request.into_inner();
|
|
||||||
let response = get_table_data(&self.db_pool, request).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_table_data_count(
|
|
||||||
&self,
|
|
||||||
request: Request<GetTableDataCountRequest>,
|
|
||||||
) -> Result<Response<CountResponse>, Status> {
|
|
||||||
let request = request.into_inner();
|
|
||||||
let response = get_table_data_count(&self.db_pool, request).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_table_data_by_position(
|
|
||||||
&self,
|
|
||||||
request: Request<GetTableDataByPositionRequest>,
|
|
||||||
) -> Result<Response<GetTableDataResponse>, Status> {
|
|
||||||
let request = request.into_inner();
|
|
||||||
let response = get_table_data_by_position(&self.db_pool, request).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// src/shared/date_utils.rs
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
|
|
||||||
/// Attempts to parse the date string with multiple commonly used formats in Slovakia
|
|
||||||
pub fn parse_date_with_multiple_formats(date_str: &str) -> Option<NaiveDate> {
|
|
||||||
// Define common date formats used in Slovakia
|
|
||||||
let formats = [
|
|
||||||
"%d:%m:%Y", // Original format: 01:01:2023
|
|
||||||
"%d.%m.%Y", // Standard Slovak format: 01.01.2023
|
|
||||||
"%d-%m-%Y", // Dash format: 01-01-2023
|
|
||||||
"%d/%m/%Y", // Slash format: 01/01/2023
|
|
||||||
"%Y-%m-%d", // ISO format: 2023-01-01
|
|
||||||
"%Y/%m/%d", // Alternative ISO: 2023/01/01
|
|
||||||
"%Y.%m.%d", // Dot ISO: 2023.01.01
|
|
||||||
"%d.%m.%y", // Short year with dot: 01.01.23
|
|
||||||
"%d-%m-%y", // Short year with dash: 01-01-23
|
|
||||||
"%d/%m/%y", // Short year with slash: 01/01/23
|
|
||||||
];
|
|
||||||
|
|
||||||
// Try each format until one works
|
|
||||||
for format in formats {
|
|
||||||
if let Ok(date) = NaiveDate::parse_from_str(date_str, format) {
|
|
||||||
return Some(date);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If none of the formats worked, try to handle potential whitespace issues
|
|
||||||
let trimmed = date_str.trim();
|
|
||||||
if trimmed != date_str {
|
|
||||||
return parse_date_with_multiple_formats(trimmed);
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// src/shared/mod.rs
|
|
||||||
pub mod date_utils;
|
|
||||||
pub mod schema_qualifier;
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// src/shared/schema_qualifier.rs
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use tonic::Status;
|
|
||||||
|
|
||||||
// TODO in the future, remove database query on every request and implement caching for scalable
|
|
||||||
// solution with many data and requests
|
|
||||||
|
|
||||||
/// Qualifies a table name by checking for its existence in the table_definitions table.
|
|
||||||
/// This is the robust, "source of truth" approach.
|
|
||||||
///
|
|
||||||
/// Rules:
|
|
||||||
/// - If a table is found in `table_definitions`, it is qualified with the 'gen' schema.
|
|
||||||
/// - Otherwise, it is assumed to be a system table in the 'public' schema.
|
|
||||||
pub async fn qualify_table_name(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
profile_name: &str,
|
|
||||||
table_name: &str,
|
|
||||||
) -> Result<String, Status> {
|
|
||||||
// Check if a definition exists for this table in the given profile.
|
|
||||||
let definition_exists = sqlx::query!(
|
|
||||||
r#"SELECT EXISTS (
|
|
||||||
SELECT 1 FROM table_definitions td
|
|
||||||
JOIN schemas s ON td.schema_id = s.id
|
|
||||||
WHERE s.name = $1 AND td.table_name = $2
|
|
||||||
)"#,
|
|
||||||
profile_name,
|
|
||||||
table_name
|
|
||||||
)
|
|
||||||
.fetch_one(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Schema lookup failed: {}", e)))?
|
|
||||||
.exists
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
if definition_exists {
|
|
||||||
Ok(format!("\"{}\".\"{}\"", profile_name, table_name))
|
|
||||||
} else {
|
|
||||||
// It's not a user-defined table, so it must be a system table in 'public.
|
|
||||||
Ok(format!("\"{}\"", table_name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Qualifies table names for data operations
|
|
||||||
pub async fn qualify_table_name_for_data(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
profile_name: &str,
|
|
||||||
table_name: &str,
|
|
||||||
) -> Result<String, Status> {
|
|
||||||
qualify_table_name(db_pool, profile_name, table_name).await
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"table_definition_id": 16,
|
|
||||||
"target_column": "idea_name",
|
|
||||||
"script": "(begin (define idea_name \"aaa\") idea_name)",
|
|
||||||
"description": "Set idea_name to Awesome Idea"
|
|
||||||
}' localhost:50051 komp_ac.table_script.TableScript/PostTableScript
|
|
||||||
{
|
|
||||||
"id": "7"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"profile_name": "script",
|
|
||||||
"table_name": "2025_berry",
|
|
||||||
"data": {
|
|
||||||
"idea_name": "sdfsfs",
|
|
||||||
"category": "Technology",
|
|
||||||
"impact_level": "High",
|
|
||||||
"is_feasible": "true",
|
|
||||||
"last_updated": "2025-03-11T12:34:56Z"
|
|
||||||
}
|
|
||||||
}' localhost:50051 komp_ac.tables_data.TablesData/PostTableData
|
|
||||||
ERROR:
|
|
||||||
Code: InvalidArgument
|
|
||||||
Message: Validation failed for 'idea_name'. Expected: 'aaa', Received: 'sdfsfs'
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"profile_name": "script",
|
|
||||||
"table_name": "2025_berry",
|
|
||||||
"data": {
|
|
||||||
"idea_name": "aaa",
|
|
||||||
"category": "Technology",
|
|
||||||
"impact_level": "High",
|
|
||||||
"is_feasible": "true",
|
|
||||||
"last_updated": "2025-03-11T12:34:56Z"
|
|
||||||
}
|
|
||||||
}' localhost:50051 komp_ac.tables_data.TablesData/PostTableData
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"message": "Data inserted successfully",
|
|
||||||
"insertedId": "1"
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
Creation of the tables:
|
|
||||||
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"table_name": "department",
|
|
||||||
"columns": [
|
|
||||||
{"name": "yearly_goal", "field_type": "text"}
|
|
||||||
],
|
|
||||||
"profile_name": "finance"
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/PostTableDefinition
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"sql": "CREATE TABLE \"2025_department\" (\n id BIGSERIAL PRIMARY KEY,\n deleted BOOLEAN NOT NULL DEFAULT FALSE,\n \"yearly_goal\" TEXT,\n created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP\n)\n"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"table_name": "project",
|
|
||||||
"columns": [
|
|
||||||
{"name": "name", "field_type": "TEXT"},
|
|
||||||
{"name": "budget_estimate", "field_type": "TEXT"}
|
|
||||||
],
|
|
||||||
"indexes": ["name"],
|
|
||||||
"profile_name": "finance",
|
|
||||||
"links": [
|
|
||||||
{"linked_table_name": "2025_department", "required": true}
|
|
||||||
]
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/PostTableDefinition
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"sql": "CREATE TABLE \"2025_project\" (\n id BIGSERIAL PRIMARY KEY,\n deleted BOOLEAN NOT NULL DEFAULT FALSE,\n \"department_id\" BIGINT NOT NULL REFERENCES \"2025_department\"(id),\n \"name\" TEXT,\n \"budget_estimate\" TEXT,\n created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP\n)\nCREATE INDEX idx_2025_project_department_fk ON \"2025_project\" (\"department_id\")\nCREATE INDEX idx_2025_project_name ON \"2025_project\" (\"name\")"
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// src/steel/mod.rs
|
|
||||||
|
|
||||||
pub mod server;
|
|
||||||
@@ -1,258 +0,0 @@
|
|||||||
// src/steel/server/execution.rs
|
|
||||||
|
|
||||||
use steel::steel_vm::engine::Engine;
|
|
||||||
use steel::steel_vm::register_fn::RegisterFn;
|
|
||||||
use steel::rvals::SteelVal;
|
|
||||||
use super::functions::SteelContext;
|
|
||||||
use steel_decimal::registry::FunctionRegistry;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use thiserror::Error;
|
|
||||||
use tracing::{debug, error};
|
|
||||||
use regex::Regex; // NEW
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Value {
|
|
||||||
Strings(Vec<String>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum ExecutionError {
|
|
||||||
#[error("Script execution failed: {0}")]
|
|
||||||
RuntimeError(String),
|
|
||||||
#[error("Type conversion error: {0}")]
|
|
||||||
TypeConversionError(String),
|
|
||||||
#[error("Unsupported target type: {0}")]
|
|
||||||
UnsupportedType(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
// NEW: upgrade steel_get_column -> steel_get_column_with_index using FK present in row_data
|
|
||||||
fn auto_promote_with_index(
|
|
||||||
script: &str,
|
|
||||||
current_table: &str,
|
|
||||||
row_data: &HashMap<String, String>,
|
|
||||||
) -> String {
|
|
||||||
// Matches: (steel_get_column "table" "column")
|
|
||||||
let re = Regex::new(
|
|
||||||
r#"\(\s*steel_get_column\s+"([^"]+)"\s+"([^"]+)"\s*\)"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
re.replace_all(script, |caps: ®ex::Captures| {
|
|
||||||
let table = caps.get(1).unwrap().as_str();
|
|
||||||
let column = caps.get(2).unwrap().as_str();
|
|
||||||
|
|
||||||
// Only upgrade cross-table calls, if FK is present in the request data
|
|
||||||
if table != current_table {
|
|
||||||
let fk_key = format!("{}_id", table);
|
|
||||||
if let Some(id_str) = row_data.get(&fk_key) {
|
|
||||||
if let Ok(_) = id_str.parse::<i64>() {
|
|
||||||
return format!(
|
|
||||||
r#"(steel_get_column_with_index "{}" {} "{}")"#,
|
|
||||||
table, id_str, column
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default: keep original call
|
|
||||||
caps.get(0).unwrap().as_str().to_string()
|
|
||||||
})
|
|
||||||
.into_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
|
||||||
|
|
||||||
// Converts row data boolean values to Steel script format during context initialization.
|
|
||||||
pub async fn convert_row_data_for_steel(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
schema_id: i64,
|
|
||||||
table_name: &str,
|
|
||||||
row_data: &mut HashMap<String, String>,
|
|
||||||
) -> Result<(), sqlx::Error> {
|
|
||||||
let table_def = sqlx::query!(
|
|
||||||
r#"
|
|
||||||
SELECT columns FROM table_definitions
|
|
||||||
WHERE schema_id = $1 AND table_name = $2
|
|
||||||
"#,
|
|
||||||
schema_id,
|
|
||||||
table_name
|
|
||||||
)
|
|
||||||
.fetch_optional(db_pool)
|
|
||||||
.await?
|
|
||||||
.ok_or_else(|| sqlx::Error::RowNotFound)?;
|
|
||||||
|
|
||||||
// Parse column definitions to identify boolean columns
|
|
||||||
if let Ok(columns) = serde_json::from_value::<Vec<ColumnDefinition>>(table_def.columns) {
|
|
||||||
for col_def in columns {
|
|
||||||
let normalized_type =
|
|
||||||
col_def.field_type.to_uppercase().split('(').next().unwrap().to_string();
|
|
||||||
|
|
||||||
if normalized_type == "BOOLEAN" || normalized_type == "BOOL" {
|
|
||||||
if let Some(value) = row_data.get_mut(&col_def.name) {
|
|
||||||
*value = match value.to_lowercase().as_str() {
|
|
||||||
"true" | "t" | "1" | "yes" | "on" => "#true".to_string(),
|
|
||||||
"false" | "f" | "0" | "no" | "off" => "#false".to_string(),
|
|
||||||
_ => value.clone(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create_steel_context_with_boolean_conversion(
|
|
||||||
current_table: String,
|
|
||||||
schema_id: i64,
|
|
||||||
schema_name: String,
|
|
||||||
mut row_data: HashMap<String, String>,
|
|
||||||
db_pool: Arc<PgPool>,
|
|
||||||
) -> Result<SteelContext, ExecutionError> {
|
|
||||||
convert_row_data_for_steel(&db_pool, schema_id, ¤t_table, &mut row_data)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("Failed to convert row data for Steel: {}", e);
|
|
||||||
ExecutionError::RuntimeError(format!("Failed to convert row data: {}", e))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(SteelContext {
|
|
||||||
current_table,
|
|
||||||
schema_id,
|
|
||||||
schema_name,
|
|
||||||
row_data,
|
|
||||||
db_pool,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute_script(
|
|
||||||
script: String,
|
|
||||||
target_type: &str,
|
|
||||||
db_pool: Arc<PgPool>,
|
|
||||||
schema_id: i64,
|
|
||||||
schema_name: String,
|
|
||||||
current_table: String,
|
|
||||||
row_data: HashMap<String, String>,
|
|
||||||
) -> Result<Value, ExecutionError> {
|
|
||||||
let mut vm = Engine::new();
|
|
||||||
|
|
||||||
// Upgrade to with_index based on FK presence in the posted data
|
|
||||||
let script = auto_promote_with_index(&script, ¤t_table, &row_data);
|
|
||||||
|
|
||||||
let context = create_steel_context_with_boolean_conversion(
|
|
||||||
current_table.clone(),
|
|
||||||
schema_id,
|
|
||||||
schema_name,
|
|
||||||
row_data.clone(),
|
|
||||||
db_pool.clone(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let context = Arc::new(context);
|
|
||||||
|
|
||||||
register_steel_functions(&mut vm, context.clone());
|
|
||||||
register_decimal_math_functions(&mut vm);
|
|
||||||
|
|
||||||
let mut define_script = String::new();
|
|
||||||
for (key, value) in &context.row_data {
|
|
||||||
define_script.push_str(&format!("(define {} \"{}\")\n", key, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
if !define_script.is_empty() {
|
|
||||||
vm.compile_and_run_raw_program(define_script)
|
|
||||||
.map_err(|e| ExecutionError::RuntimeError(format!(
|
|
||||||
"Failed to register variables: {}",
|
|
||||||
e
|
|
||||||
)))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
FunctionRegistry::register_variables(&mut vm, context.row_data.clone());
|
|
||||||
|
|
||||||
let results = vm
|
|
||||||
.compile_and_run_raw_program(script.clone())
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("Steel script execution failed: {}", e);
|
|
||||||
error!("Script was: {}", script);
|
|
||||||
error!("Available variables were: {:?}", context.row_data);
|
|
||||||
ExecutionError::RuntimeError(e.to_string())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
match target_type {
|
|
||||||
"STRINGS" => process_string_results(results),
|
|
||||||
_ => Err(ExecutionError::UnsupportedType(target_type.into())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_steel_functions(vm: &mut Engine, context: Arc<SteelContext>) {
|
|
||||||
debug!("Registering Steel functions with context");
|
|
||||||
|
|
||||||
vm.register_fn("steel_get_column", {
|
|
||||||
let ctx = context.clone();
|
|
||||||
move |table: String, column: String| {
|
|
||||||
debug!(
|
|
||||||
"steel_get_column called with table: '{}', column: '{}'",
|
|
||||||
table, column
|
|
||||||
);
|
|
||||||
ctx.steel_get_column(&table, &column)
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("steel_get_column failed: {:?}", e);
|
|
||||||
e.to_string()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
vm.register_fn("steel_get_column_with_index", {
|
|
||||||
let ctx = context.clone();
|
|
||||||
move |table: String, index: i64, column: String| {
|
|
||||||
debug!(
|
|
||||||
"steel_get_column_with_index called with table: '{}', index: {}, column: '{}'",
|
|
||||||
table, index, column
|
|
||||||
);
|
|
||||||
ctx.steel_get_column_with_index(&table, index, &column)
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("steel_get_column_with_index failed: {:?}", e);
|
|
||||||
e.to_string()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
vm.register_fn("steel_query_sql", {
|
|
||||||
let ctx = context.clone();
|
|
||||||
move |query: String| {
|
|
||||||
debug!("steel_query_sql called with query: '{}'", query);
|
|
||||||
ctx.steel_query_sql(&query).map_err(|e| {
|
|
||||||
error!("steel_query_sql failed: {:?}", e);
|
|
||||||
e.to_string()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_decimal_math_functions(vm: &mut Engine) {
|
|
||||||
debug!("Registering decimal math functions");
|
|
||||||
FunctionRegistry::register_all(vm);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn process_string_results(results: Vec<SteelVal>) -> Result<Value, ExecutionError> {
|
|
||||||
let mut strings = Vec::new();
|
|
||||||
|
|
||||||
for result in results {
|
|
||||||
let result_str = match result {
|
|
||||||
SteelVal::StringV(s) => s.to_string(),
|
|
||||||
SteelVal::NumV(n) => n.to_string(),
|
|
||||||
SteelVal::IntV(i) => i.to_string(),
|
|
||||||
SteelVal::BoolV(b) => b.to_string(),
|
|
||||||
_ => {
|
|
||||||
error!("Unexpected result type: {:?}", result);
|
|
||||||
return Err(ExecutionError::TypeConversionError(
|
|
||||||
format!("Expected string-convertible type, got {:?}", result),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
strings.push(result_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Value::Strings(strings))
|
|
||||||
}
|
|
||||||
@@ -1,322 +0,0 @@
|
|||||||
// src/steel/server/functions.rs
|
|
||||||
|
|
||||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
|
||||||
use steel::rvals::SteelVal;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use thiserror::Error;
|
|
||||||
use sqlx::Row;
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum FunctionError {
|
|
||||||
#[error("Column not found: {0}")]
|
|
||||||
ColumnNotFound(String),
|
|
||||||
#[error("Foreign key not found: {0}")]
|
|
||||||
ForeignKeyNotFound(String),
|
|
||||||
#[error("Table not found: {0}")]
|
|
||||||
TableNotFound(String),
|
|
||||||
#[error("Database error: {0}")]
|
|
||||||
DatabaseError(String),
|
|
||||||
#[error("Prohibited data type access: {0}")]
|
|
||||||
ProhibitedTypeAccess(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
const PROHIBITED_TYPES: &[&str] = &["BIGINT", "DATE", "TIMESTAMPTZ"];
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct SteelContext {
|
|
||||||
pub current_table: String,
|
|
||||||
pub schema_id: i64,
|
|
||||||
pub schema_name: String,
|
|
||||||
pub row_data: HashMap<String, String>,
|
|
||||||
pub db_pool: Arc<PgPool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SteelContext {
|
|
||||||
async fn get_column_type(
|
|
||||||
&self,
|
|
||||||
table_name: &str,
|
|
||||||
column_name: &str,
|
|
||||||
) -> Result<String, FunctionError> {
|
|
||||||
let table_def = sqlx::query!(
|
|
||||||
r#"SELECT columns FROM table_definitions
|
|
||||||
WHERE schema_id = $1 AND table_name = $2"#,
|
|
||||||
self.schema_id,
|
|
||||||
table_name
|
|
||||||
)
|
|
||||||
.fetch_optional(&*self.db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| FunctionError::DatabaseError(e.to_string()))?
|
|
||||||
.ok_or_else(|| FunctionError::TableNotFound(table_name.to_string()))?;
|
|
||||||
|
|
||||||
let columns: Vec<ColumnDefinition> = serde_json::from_value(table_def.columns)
|
|
||||||
.map_err(|e| FunctionError::DatabaseError(format!(
|
|
||||||
"Invalid column data: {}",
|
|
||||||
e
|
|
||||||
)))?;
|
|
||||||
|
|
||||||
for col_def in columns {
|
|
||||||
if col_def.name == column_name {
|
|
||||||
return Ok(col_def.field_type.to_uppercase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(FunctionError::ColumnNotFound(format!(
|
|
||||||
"Column '{}' not found in table '{}'",
|
|
||||||
column_name, table_name
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert_value_to_steel_format(&self, value: &str, column_type: &str) -> String {
|
|
||||||
let normalized_type = normalize_data_type(column_type);
|
|
||||||
|
|
||||||
match normalized_type.as_str() {
|
|
||||||
"BOOLEAN" | "BOOL" => match value.to_lowercase().as_str() {
|
|
||||||
"true" | "t" | "1" | "yes" | "on" => "#true".to_string(),
|
|
||||||
"false" | "f" | "0" | "no" | "off" => "#false".to_string(),
|
|
||||||
_ => value.to_string(),
|
|
||||||
},
|
|
||||||
"INTEGER" => value.to_string(),
|
|
||||||
_ => value.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn validate_column_type_and_get_type(
|
|
||||||
&self,
|
|
||||||
table_name: &str,
|
|
||||||
column_name: &str,
|
|
||||||
) -> Result<String, FunctionError> {
|
|
||||||
let column_type = self.get_column_type(table_name, column_name).await?;
|
|
||||||
|
|
||||||
if is_prohibited_type(&column_type) {
|
|
||||||
return Err(FunctionError::ProhibitedTypeAccess(format!(
|
|
||||||
"Cannot access column '{}' in table '{}' because it has prohibited type '{}'. Steel scripts cannot access columns of type: {}",
|
|
||||||
column_name,
|
|
||||||
table_name,
|
|
||||||
column_type,
|
|
||||||
PROHIBITED_TYPES.join(", ")
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(column_type)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn steel_get_column(
|
|
||||||
&self,
|
|
||||||
table: &str,
|
|
||||||
column: &str,
|
|
||||||
) -> Result<SteelVal, SteelVal> {
|
|
||||||
if table == self.current_table {
|
|
||||||
// current table
|
|
||||||
let column_type = tokio::task::block_in_place(|| {
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
|
||||||
handle.block_on(async {
|
|
||||||
self.validate_column_type_and_get_type(table, column).await
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
let column_type = match column_type {
|
|
||||||
Ok(ct) => ct,
|
|
||||||
Err(e) => return Err(SteelVal::StringV(e.to_string().into())),
|
|
||||||
};
|
|
||||||
|
|
||||||
return self
|
|
||||||
.row_data
|
|
||||||
.get(column)
|
|
||||||
.map(|v| {
|
|
||||||
let converted =
|
|
||||||
self.convert_value_to_steel_format(v, &column_type);
|
|
||||||
SteelVal::StringV(converted.into())
|
|
||||||
})
|
|
||||||
.ok_or_else(|| {
|
|
||||||
SteelVal::StringV(
|
|
||||||
format!("Column {} not found", column).into(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cross-table via FK: use exact table name FK convention: "<table>_id"
|
|
||||||
let result = tokio::task::block_in_place(|| {
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
|
||||||
handle.block_on(async {
|
|
||||||
let fk_column = format!("{}_id", table);
|
|
||||||
let fk_value = self
|
|
||||||
.row_data
|
|
||||||
.get(&fk_column)
|
|
||||||
.ok_or_else(|| {
|
|
||||||
FunctionError::ForeignKeyNotFound(format!(
|
|
||||||
"Foreign key column '{}' not found on '{}'",
|
|
||||||
fk_column, self.current_table
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let column_type =
|
|
||||||
self.validate_column_type_and_get_type(table, column)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let raw_value = sqlx::query_scalar::<_, String>(&format!(
|
|
||||||
"SELECT \"{}\" FROM \"{}\".\"{}\" WHERE id = $1",
|
|
||||||
column, self.schema_name, table
|
|
||||||
))
|
|
||||||
.bind(
|
|
||||||
fk_value
|
|
||||||
.parse::<i64>()
|
|
||||||
.map_err(|_| {
|
|
||||||
FunctionError::DatabaseError(
|
|
||||||
"Invalid foreign key format".into(),
|
|
||||||
)
|
|
||||||
})?,
|
|
||||||
)
|
|
||||||
.fetch_one(&*self.db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| FunctionError::DatabaseError(e.to_string()))?;
|
|
||||||
|
|
||||||
let converted =
|
|
||||||
self.convert_value_to_steel_format(&raw_value, &column_type);
|
|
||||||
Ok::<String, FunctionError>(converted)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(v) => Ok(SteelVal::StringV(v.into())),
|
|
||||||
Err(e) => Err(SteelVal::StringV(e.to_string().into())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn steel_get_column_with_index(
|
|
||||||
&self,
|
|
||||||
table: &str,
|
|
||||||
index: i64,
|
|
||||||
column: &str,
|
|
||||||
) -> Result<SteelVal, SteelVal> {
|
|
||||||
// Cross-table: interpret 'index' as the row id to fetch directly
|
|
||||||
if table != self.current_table {
|
|
||||||
let result = tokio::task::block_in_place(|| {
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
|
||||||
handle.block_on(async {
|
|
||||||
let column_type =
|
|
||||||
self.validate_column_type_and_get_type(table, column)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let raw_value = sqlx::query_scalar::<_, String>(&format!(
|
|
||||||
"SELECT \"{}\" FROM \"{}\".\"{}\" WHERE id = $1",
|
|
||||||
column, self.schema_name, table
|
|
||||||
))
|
|
||||||
.bind(index)
|
|
||||||
.fetch_one(&*self.db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| FunctionError::DatabaseError(e.to_string()))?;
|
|
||||||
|
|
||||||
let converted = self
|
|
||||||
.convert_value_to_steel_format(&raw_value, &column_type);
|
|
||||||
Ok::<String, FunctionError>(converted)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
return match result {
|
|
||||||
Ok(v) => Ok(SteelVal::StringV(v.into())),
|
|
||||||
Err(e) => Err(SteelVal::StringV(e.to_string().into())),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Current table: existing behavior (index in comma-separated string)
|
|
||||||
let value = self.steel_get_column(table, column)?;
|
|
||||||
if let SteelVal::StringV(s) = value {
|
|
||||||
let parts: Vec<_> = s.split(',').collect();
|
|
||||||
if let Some(part) = parts.get(index as usize) {
|
|
||||||
let trimmed = part.trim();
|
|
||||||
|
|
||||||
let column_type = tokio::task::block_in_place(|| {
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
|
||||||
handle.block_on(async {
|
|
||||||
self.get_column_type(table, column).await
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
match column_type {
|
|
||||||
Ok(ct) => {
|
|
||||||
let converted =
|
|
||||||
self.convert_value_to_steel_format(trimmed, &ct);
|
|
||||||
Ok(SteelVal::StringV(converted.into()))
|
|
||||||
}
|
|
||||||
Err(_) => Ok(SteelVal::StringV(trimmed.into())),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(SteelVal::StringV("Index out of bounds".into()))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(SteelVal::StringV(
|
|
||||||
"Expected comma-separated string".into(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn steel_query_sql(&self, query: &str) -> Result<SteelVal, SteelVal> {
|
|
||||||
if !is_read_only_query(query) {
|
|
||||||
return Err(SteelVal::StringV("Only SELECT queries are allowed".into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if contains_prohibited_column_access(query) {
|
|
||||||
return Err(SteelVal::StringV(
|
|
||||||
format!(
|
|
||||||
"SQL query may access prohibited column types. Steel scripts cannot access columns of type: {}",
|
|
||||||
PROHIBITED_TYPES.join(", ")
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let pool = self.db_pool.clone();
|
|
||||||
|
|
||||||
let result = tokio::task::block_in_place(|| {
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
|
||||||
handle.block_on(async {
|
|
||||||
let rows = sqlx::query(query)
|
|
||||||
.fetch_all(&*pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| SteelVal::StringV(e.to_string().into()))?;
|
|
||||||
|
|
||||||
let mut results = Vec::new();
|
|
||||||
for row in rows {
|
|
||||||
let val: String = row
|
|
||||||
.try_get(0)
|
|
||||||
.map_err(|e| SteelVal::StringV(e.to_string().into()))?;
|
|
||||||
results.push(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(results.join(","))
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
result.map(|s| SteelVal::StringV(s.into()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_prohibited_type(data_type: &str) -> bool {
|
|
||||||
let normalized_type = normalize_data_type(data_type);
|
|
||||||
PROHIBITED_TYPES
|
|
||||||
.iter()
|
|
||||||
.any(|&prohibited| normalized_type.starts_with(prohibited))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn normalize_data_type(data_type: &str) -> String {
|
|
||||||
data_type
|
|
||||||
.to_uppercase()
|
|
||||||
.split('(')
|
|
||||||
.next()
|
|
||||||
.unwrap_or(data_type)
|
|
||||||
.trim()
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn contains_prohibited_column_access(query: &str) -> bool {
|
|
||||||
let query_upper = query.to_uppercase();
|
|
||||||
let patterns = ["EXTRACT(", "DATE_PART(", "::DATE", "::TIMESTAMPTZ", "::BIGINT"];
|
|
||||||
patterns.iter().any(|p| query_upper.contains(p))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_read_only_query(query: &str) -> bool {
|
|
||||||
let query = query.trim_start().to_uppercase();
|
|
||||||
query.starts_with("SELECT") || query.starts_with("SHOW") || query.starts_with("EXPLAIN")
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// src/steel/server/mod.rs
|
|
||||||
pub mod execution;
|
|
||||||
pub mod functions;
|
|
||||||
|
|
||||||
pub use execution::*;
|
|
||||||
pub use functions::*;
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"table_name": "company_data1",
|
|
||||||
"columns": [
|
|
||||||
{"name": "company_name", "field_type": "text"},
|
|
||||||
{"name": "textfield", "field_type": "text"},
|
|
||||||
{"name": "textfield2", "field_type": "text"},
|
|
||||||
{"name": "textfield3", "field_type": "text"},
|
|
||||||
{"name": "headquarters_psc", "field_type": "psc"},
|
|
||||||
{"name": "contact_phone", "field_type": "phone"},
|
|
||||||
{"name": "office_address", "field_type": "address"},
|
|
||||||
{"name": "support_email", "field_type": "email"},
|
|
||||||
{"name": "is_active", "field_type": "boolean"},
|
|
||||||
{"name": "last_updated", "field_type": "timestamp"}
|
|
||||||
],
|
|
||||||
"indexes": ["company_name", "is_active"],
|
|
||||||
"profile_name": "default",
|
|
||||||
"linked_table_name": ""
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/PostTableDefinition
|
|
||||||
ERROR:
|
|
||||||
Code: NotFound
|
|
||||||
Message: Linked table not found in profile
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"table_name": "company_data1",
|
|
||||||
"columns": [
|
|
||||||
{"name": "company_name", "field_type": "text"},
|
|
||||||
{"name": "textfield", "field_type": "text"},
|
|
||||||
{"name": "textfield2", "field_type": "text"},
|
|
||||||
{"name": "textfield3", "field_type": "text"},
|
|
||||||
{"name": "headquarters_psc", "field_type": "psc"},
|
|
||||||
{"name": "contact_phone", "field_type": "phone"},
|
|
||||||
{"name": "office_address", "field_type": "address"},
|
|
||||||
{"name": "support_email", "field_type": "email"},
|
|
||||||
{"name": "is_active", "field_type": "boolean"},
|
|
||||||
{"name": "last_updated", "field_type": "timestamp"}
|
|
||||||
],
|
|
||||||
"indexes": ["company_name", "is_active"],
|
|
||||||
"profile_name": "default"
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/PostTableDefinition
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"sql": "CREATE TABLE \"2025_company_data1\" (\n id BIGSERIAL PRIMARY KEY,\n deleted BOOLEAN NOT NULL DEFAULT FALSE,\n firma TEXT NOT NULL,\n \"company_name\" TEXT,\n \"textfield\" TEXT,\n \"textfield2\" TEXT,\n \"textfield3\" TEXT,\n \"headquarters_psc\" TEXT,\n \"contact_phone\" VARCHAR(15),\n \"office_address\" TEXT,\n \"support_email\" VARCHAR(255),\n \"is_active\" BOOLEAN,\n \"last_updated\" TIMESTAMPTZ,\n created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP\n)\nCREATE INDEX idx_2025_company_data1_firma ON \"2025_company_data1\" (firma)\nCREATE INDEX idx_2025_company_data1_company_name ON \"2025_company_data1\" (\"company_name\")\nCREATE INDEX idx_2025_company_data1_is_active ON \"2025_company_data1\" (\"is_active\")"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{}' localhost:50051 komp_ac.table_definition.TableDefinition/GetProfileTree
|
|
||||||
{
|
|
||||||
"profiles": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"name": "2025_company_data1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"profile_name": "default",
|
|
||||||
"table_name": "2025_company_data1"
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/DeleteTable
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"message": "Table '2025_company_data1' and its definition were successfully removed"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{}' localhost:50051 komp_ac.table_definition.TableDefinition/GetProfileTree
|
|
||||||
{}
|
|
||||||
╭─ ~/Doc/pr/komp_ac/server main ⇡1 ········· ✔
|
|
||||||
╰─
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{}' localhost:50051 komp_ac.table_definition.TableDefinition/GetProfileTree
|
|
||||||
{
|
|
||||||
"profiles": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"name": "ud_2025_test_table_no_linked"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_test_table"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "new_profile",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"name": "ud_2025_multi_dependent_table2",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_linked_test_table2"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_multi_dependent_table",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_linked_test_table2"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_linked_test_table2",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_profile_table"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_multi_dependent_table3",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_multi_dependent_table2"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_linked_test_table3",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_profile_table"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_multi_dependent_table4",
|
|
||||||
"dependsOn": [
|
|
||||||
"2025_multi_dependent_table3"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_linked_test_table",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_profile_table"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_profile_table"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"table_name": "multi_dependent_table5",
|
|
||||||
"columns": [
|
|
||||||
{"name": "column1", "data_type": "TEXT"},
|
|
||||||
{"name": "columnx", "data_type": "TEXT"},
|
|
||||||
{"name": "columny", "data_type": "TEXT"},
|
|
||||||
{"name": "columnz", "data_type": "TEXT"},
|
|
||||||
{"name": "columna", "data_type": "TEXT"},
|
|
||||||
{"name": "columnb", "data_type": "TEXT"},
|
|
||||||
{"name": "columnc", "data_type": "TEXT"},
|
|
||||||
{"name": "columnd", "data_type": "TEXT"},
|
|
||||||
{"name": "column2", "data_type": "INTEGER"}
|
|
||||||
],
|
|
||||||
"indexes": ["column1", "columnd"],
|
|
||||||
"profile_name": "new_profile",
|
|
||||||
"linked_table_name": "2025_multi_dependent_table3"
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/PostTableDefinition
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"sql": "CREATE TABLE \"2025_multi_dependent_table5\" (\n id BIGSERIAL PRIMARY KEY,\n deleted BOOLEAN NOT NULL DEFAULT FALSE,\n firma TEXT NOT NULL,\n \"multi_dependent_table3_id\" BIGINT NOT NULL REFERENCES \"2025_multi_dependent_table3\"(id),\n \"2025_column1\" TEXT,\n \"2025_columnx\" TEXT,\n \"2025_columny\" TEXT,\n \"2025_columnz\" TEXT,\n \"2025_columna\" TEXT,\n \"2025_columnb\" TEXT,\n \"2025_columnc\" TEXT,\n \"2025_columnd\" TEXT,\n \"2025_column2\" INTEGER,\n created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP\n)\nCREATE INDEX idx_2025_multi_dependent_table5_firma ON \"2025_multi_dependent_table5\" (firma)\nCREATE INDEX idx_2025_multi_dependent_table5_multi_dependent_table3_id ON \"2025_multi_dependent_table5\" (\"multi_dependent_table3_id\")\nCREATE INDEX idx_2025_multi_dependent_table5_2025_column1 ON \"2025_multi_dependent_table5\" (\"2025_column1\")\nCREATE INDEX idx_2025_multi_dependent_table5_2025_columnd ON \"2025_multi_dependent_table5\" (\"2025_columnd\")"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{}' localhost:50051 komp_ac.table_definition.TableDefinition/GetProfileTree
|
|
||||||
{
|
|
||||||
"profiles": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"name": "ud_2025_test_table_no_linked"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_test_table"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "new_profile",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"name": "ud_2025_linked_test_table",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_profile_table"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_multi_dependent_table2",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_linked_test_table2"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_multi_dependent_table3",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_multi_dependent_table2"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_profile_table"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_linked_test_table3",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_profile_table"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_multi_dependent_table4",
|
|
||||||
"dependsOn": [
|
|
||||||
"2025_multi_dependent_table3"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_multi_dependent_table5",
|
|
||||||
"dependsOn": [
|
|
||||||
"2025_multi_dependent_table3"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_multi_dependent_table",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_linked_test_table2"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ud_2025_linked_test_table2",
|
|
||||||
"dependsOn": [
|
|
||||||
"ud_2025_profile_table"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{}' localhost:50051 komp_ac.table_definition.TableDefinition/GetProfileTree
|
|
||||||
{
|
|
||||||
"profiles": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"name": "2025_adresar3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar5"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar4"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"table_name": "adresar6",
|
|
||||||
"columns": [
|
|
||||||
{"name": "firma", "field_type": "text"},
|
|
||||||
{"name": "kz", "field_type": "text"},
|
|
||||||
{"name": "drc", "field_type": "text"},
|
|
||||||
{"name": "ulica", "field_type": "text"},
|
|
||||||
{"name": "psc", "field_type": "psc"},
|
|
||||||
{"name": "mesto", "field_type": "text"},
|
|
||||||
{"name": "stat", "field_type": "text"},
|
|
||||||
{"name": "banka", "field_type": "text"},
|
|
||||||
{"name": "ucet", "field_type": "text"},
|
|
||||||
{"name": "skladm", "field_type": "text"},
|
|
||||||
{"name": "ico", "field_type": "text"},
|
|
||||||
{"name": "kontakt", "field_type": "text"},
|
|
||||||
{"name": "telefon", "field_type": "phone"},
|
|
||||||
{"name": "skladu", "field_type": "text"},
|
|
||||||
{"name": "fax", "field_type": "text"}
|
|
||||||
],
|
|
||||||
"indexes": ["firma", "mesto"],
|
|
||||||
"profile_name": "default"
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/PostTableDefinition
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"sql": "CREATE TABLE \"2025_adresar6\" (\n id BIGSERIAL PRIMARY KEY,\n deleted BOOLEAN NOT NULL DEFAULT FALSE,\n \"firma\" TEXT,\n \"kz\" TEXT,\n \"drc\" TEXT,\n \"ulica\" TEXT,\n \"psc\" TEXT,\n \"mesto\" TEXT,\n \"stat\" TEXT,\n \"banka\" TEXT,\n \"ucet\" TEXT,\n \"skladm\" TEXT,\n \"ico\" TEXT,\n \"kontakt\" TEXT,\n \"telefon\" VARCHAR(15),\n \"skladu\" TEXT,\n \"fax\" TEXT,\n created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP\n)\nCREATE INDEX idx_2025_adresar6_firma ON \"2025_adresar6\" (\"firma\")\nCREATE INDEX idx_2025_adresar6_mesto ON \"2025_adresar6\" (\"mesto\")"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{}' localhost:50051 komp_ac.table_definition.TableDefinition/GetProfileTree
|
|
||||||
{
|
|
||||||
"profiles": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"name": "2025_adresar2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "2025_adresar5"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
❯ psql -U multi_psql_dev -d multi_rust_dev
|
|
||||||
|
|
||||||
psql (17.2)
|
|
||||||
Type "help" for help.
|
|
||||||
|
|
||||||
multi_rust_dev=> \dt
|
|
||||||
List of relations
|
|
||||||
Schema | Name | Type | Owner
|
|
||||||
--------+-------------------+-------+----------------
|
|
||||||
public | 2025_adresar | table | multi_psql_dev
|
|
||||||
public | 2025_adresar2 | table | multi_psql_dev
|
|
||||||
public | 2025_adresar5 | table | multi_psql_dev
|
|
||||||
public | 2025_adresar6 | table | multi_psql_dev
|
|
||||||
public | _sqlx_migrations | table | multi_psql_dev
|
|
||||||
public | adresar | table | multi_psql_dev
|
|
||||||
public | profiles | table | multi_psql_dev
|
|
||||||
public | table_definitions | table | multi_psql_dev
|
|
||||||
public | table_scripts | table | multi_psql_dev
|
|
||||||
public | uctovnictvo | table | multi_psql_dev
|
|
||||||
(10 rows)
|
|
||||||
|
|
||||||
multi_rust_dev=> \d "2025_adresar6";
|
|
||||||
Table "public.2025_adresar6"
|
|
||||||
Column | Type | Collation | Nullable | Default
|
|
||||||
------------+--------------------------+-----------+----------+---------------------------------------------
|
|
||||||
id | bigint | | not null | nextval('"2025_adresar6_id_seq"'::regclass)
|
|
||||||
deleted | boolean | | not null | false
|
|
||||||
firma | text | | |
|
|
||||||
kz | text | | |
|
|
||||||
drc | text | | |
|
|
||||||
ulica | text | | |
|
|
||||||
psc | text | | |
|
|
||||||
mesto | text | | |
|
|
||||||
stat | text | | |
|
|
||||||
banka | text | | |
|
|
||||||
ucet | text | | |
|
|
||||||
skladm | text | | |
|
|
||||||
ico | text | | |
|
|
||||||
kontakt | text | | |
|
|
||||||
telefon | character varying(15) | | |
|
|
||||||
skladu | text | | |
|
|
||||||
fax | text | | |
|
|
||||||
created_at | timestamp with time zone | | | CURRENT_TIMESTAMP
|
|
||||||
Indexes:
|
|
||||||
"2025_adresar6_pkey" PRIMARY KEY, btree (id)
|
|
||||||
"idx_2025_adresar6_firma" btree (firma)
|
|
||||||
"idx_2025_adresar6_mesto" btree (mesto)
|
|
||||||
|
|
||||||
multi_rust_dev=>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
grpcurl -plaintext -d '{
|
|
||||||
"table_name": "project_management4",
|
|
||||||
"columns": [
|
|
||||||
{"name": "project_name", "field_type": "text"},
|
|
||||||
{"name": "description", "field_type": "text"},
|
|
||||||
{"name": "budget", "field_type": "text"},
|
|
||||||
{"name": "is_active", "field_type": "boolean"},
|
|
||||||
{"name": "deadline", "field_type": "timestamp"}
|
|
||||||
],
|
|
||||||
"indexes": ["project_name", "is_active", "deadline"],
|
|
||||||
"profile_name": "default",
|
|
||||||
"links": [
|
|
||||||
{"linked_table_name": "2025_customer", "required": true},
|
|
||||||
{"linked_table_name": "2025_product", "required": false},
|
|
||||||
{"linked_table_name": "2025_author", "required": true},
|
|
||||||
{"linked_table_name": "2025_order", "required": false},
|
|
||||||
{"linked_table_name": "2025_shipping_provider", "required": false},
|
|
||||||
{"linked_table_name": "2025_ecom_product", "required": false}
|
|
||||||
]
|
|
||||||
}' localhost:50051 komp_ac.table_definition.TableDefinition/PostTableDefinition
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// server/src/table_definition/handlers.rs
|
|
||||||
pub mod post_table_definition;
|
|
||||||
pub mod get_profile_tree;
|
|
||||||
pub mod delete_table;
|
|
||||||
|
|
||||||
pub use post_table_definition::post_table_definition;
|
|
||||||
pub use get_profile_tree::get_profile_tree;
|
|
||||||
pub use delete_table::delete_table;
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
// src/table_definition/handlers/delete_table.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use common::proto::komp_ac::table_definition::{DeleteTableRequest, DeleteTableResponse};
|
|
||||||
|
|
||||||
pub async fn delete_table(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: DeleteTableRequest,
|
|
||||||
) -> Result<DeleteTableResponse, Status> {
|
|
||||||
let mut transaction = db_pool.begin().await
|
|
||||||
.map_err(|e| Status::internal(format!("Failed to start transaction: {}", e)))?;
|
|
||||||
|
|
||||||
// Step 1: Get schema and validate existence
|
|
||||||
let schema = sqlx::query!(
|
|
||||||
"SELECT id, name FROM schemas WHERE name = $1",
|
|
||||||
request.profile_name
|
|
||||||
)
|
|
||||||
.fetch_optional(&mut *transaction)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Schema lookup failed: {}", e)))?;
|
|
||||||
|
|
||||||
let (schema_id, schema_name) = match schema {
|
|
||||||
Some(s) => (s.id, s.name),
|
|
||||||
None => return Err(Status::not_found("Profile not found")),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Step 2: Get table definition and validate existence
|
|
||||||
let table_def = sqlx::query!(
|
|
||||||
"SELECT id FROM table_definitions
|
|
||||||
WHERE schema_id = $1 AND table_name = $2",
|
|
||||||
schema_id,
|
|
||||||
request.table_name
|
|
||||||
)
|
|
||||||
.fetch_optional(&mut *transaction)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Table lookup failed: {}", e)))?;
|
|
||||||
|
|
||||||
let table_def_id = match table_def {
|
|
||||||
Some(t) => t.id,
|
|
||||||
None => return Err(Status::not_found("Table not found in profile")),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Step 3: Drop the actual PostgreSQL table with CASCADE (schema-qualified)
|
|
||||||
let drop_table_sql = format!(r#"DROP TABLE IF EXISTS "{}"."{}" CASCADE"#, schema_name, request.table_name);
|
|
||||||
sqlx::query(&drop_table_sql)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Table drop failed: {}", e)))?;
|
|
||||||
|
|
||||||
// Step 4: Delete from table_definitions
|
|
||||||
sqlx::query!(
|
|
||||||
"DELETE FROM table_definitions WHERE id = $1",
|
|
||||||
table_def_id
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Definition deletion failed: {}", e)))?;
|
|
||||||
|
|
||||||
// Step 5: Check and clean up schema if empty
|
|
||||||
let remaining = sqlx::query!(
|
|
||||||
"SELECT COUNT(*) as count FROM table_definitions WHERE schema_id = $1",
|
|
||||||
schema_id
|
|
||||||
)
|
|
||||||
.fetch_one(&mut *transaction)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Count query failed: {}", e)))?;
|
|
||||||
|
|
||||||
if remaining.count.unwrap_or(1) == 0 {
|
|
||||||
// Drop the PostgreSQL schema if empty
|
|
||||||
let drop_schema_sql = format!(r#"DROP SCHEMA IF EXISTS "{}" CASCADE"#, schema_name);
|
|
||||||
sqlx::query(&drop_schema_sql)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Schema drop failed: {}", e)))?;
|
|
||||||
|
|
||||||
// Delete the schema record
|
|
||||||
sqlx::query!(
|
|
||||||
"DELETE FROM schemas WHERE id = $1",
|
|
||||||
schema_id
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Schema cleanup failed: {}", e)))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
transaction.commit().await
|
|
||||||
.map_err(|e| Status::internal(format!("Transaction commit failed: {}", e)))?;
|
|
||||||
|
|
||||||
Ok(DeleteTableResponse {
|
|
||||||
success: true,
|
|
||||||
message: format!("Table '{}' and its definition were successfully removed", request.table_name),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
// src/table_definition/handlers/get_profile_tree.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use common::proto::komp_ac::{
|
|
||||||
common::Empty,
|
|
||||||
table_definition::{
|
|
||||||
ProfileTreeResponse,
|
|
||||||
profile_tree_response::{Table, Profile}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub async fn get_profile_tree(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
_request: Request<Empty>,
|
|
||||||
) -> Result<Response<ProfileTreeResponse>, Status> {
|
|
||||||
let mut profiles = Vec::new();
|
|
||||||
|
|
||||||
// Get all schemas (internally changed from profiles to schemas)
|
|
||||||
let schema_records = sqlx::query!(
|
|
||||||
"SELECT id, name FROM schemas ORDER BY name"
|
|
||||||
)
|
|
||||||
.fetch_all(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Failed to fetch schemas: {}", e)))?;
|
|
||||||
|
|
||||||
for schema in schema_records {
|
|
||||||
// Get all tables with their dependencies from the links table
|
|
||||||
let tables = sqlx::query!(
|
|
||||||
r#"
|
|
||||||
SELECT
|
|
||||||
td.id as table_id,
|
|
||||||
td.table_name,
|
|
||||||
COALESCE(
|
|
||||||
json_agg(
|
|
||||||
json_build_object(
|
|
||||||
'linked_name', ltd.table_name,
|
|
||||||
'required', tdl.is_required
|
|
||||||
)
|
|
||||||
) FILTER (WHERE ltd.id IS NOT NULL),
|
|
||||||
'[]'::json
|
|
||||||
) as dependencies
|
|
||||||
FROM table_definitions td
|
|
||||||
LEFT JOIN table_definition_links tdl ON td.id = tdl.source_table_id
|
|
||||||
LEFT JOIN table_definitions ltd ON tdl.linked_table_id = ltd.id
|
|
||||||
WHERE td.schema_id = $1
|
|
||||||
GROUP BY td.id, td.table_name
|
|
||||||
ORDER BY td.table_name
|
|
||||||
"#,
|
|
||||||
schema.id
|
|
||||||
)
|
|
||||||
.fetch_all(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Failed to fetch tables: {}", e)))?;
|
|
||||||
|
|
||||||
// Convert to protobuf format
|
|
||||||
let proto_tables = tables.into_iter()
|
|
||||||
.map(|record| {
|
|
||||||
// Handle the Option<Value> properly
|
|
||||||
let dependencies = record.dependencies
|
|
||||||
.map(|val| serde_json::from_value::<Vec<serde_json::Value>>(val))
|
|
||||||
.transpose()
|
|
||||||
.unwrap_or_else(|_| Some(Vec::new()))
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
Table {
|
|
||||||
id: record.table_id,
|
|
||||||
name: record.table_name,
|
|
||||||
depends_on: dependencies
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|d| d["linked_name"].as_str().map(|s| s.to_string()))
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// External API still returns "profiles" for compatibility
|
|
||||||
profiles.push(Profile {
|
|
||||||
name: schema.name,
|
|
||||||
tables: proto_tables
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Response::new(ProfileTreeResponse { profiles }))
|
|
||||||
}
|
|
||||||
@@ -1,369 +0,0 @@
|
|||||||
// src/table_definition/handlers/post_table_definition.rs
|
|
||||||
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::{PgPool, Transaction, Postgres};
|
|
||||||
use common::proto::komp_ac::table_definition::{PostTableDefinitionRequest, TableDefinitionResponse};
|
|
||||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
|
||||||
use crate::table_definition::models::map_field_type;
|
|
||||||
|
|
||||||
// NEW: Helper function to provide detailed error messages
|
|
||||||
fn validate_identifier_format(s: &str, identifier_type: &str) -> Result<(), Status> {
|
|
||||||
if s.is_empty() {
|
|
||||||
return Err(Status::invalid_argument(format!("{} cannot be empty", identifier_type)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.starts_with('_') {
|
|
||||||
return Err(Status::invalid_argument(format!("{} cannot start with underscore", identifier_type)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.chars().next().unwrap().is_ascii_digit() {
|
|
||||||
return Err(Status::invalid_argument(format!("{} cannot start with a number", identifier_type)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for invalid characters
|
|
||||||
let invalid_chars: Vec<char> = s.chars()
|
|
||||||
.filter(|c| !c.is_ascii_lowercase() && !c.is_ascii_digit() && *c != '_')
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if !invalid_chars.is_empty() {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"{} contains invalid characters: {:?}. Only lowercase letters, numbers, and underscores are allowed",
|
|
||||||
identifier_type, invalid_chars
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for uppercase letters specifically to give a helpful message
|
|
||||||
if s.chars().any(|c| c.is_ascii_uppercase()) {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"{} contains uppercase letters. Only lowercase letters are allowed",
|
|
||||||
identifier_type
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_invalid_table_name(table_name: &str) -> bool {
|
|
||||||
table_name.ends_with("_id") ||
|
|
||||||
table_name == "id" ||
|
|
||||||
table_name == "deleted" ||
|
|
||||||
table_name == "created_at"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_reserved_schema(schema_name: &str) -> bool {
|
|
||||||
let lower = schema_name.to_lowercase();
|
|
||||||
lower == "public" ||
|
|
||||||
lower == "information_schema" ||
|
|
||||||
lower.starts_with("pg_")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn post_table_definition(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: PostTableDefinitionRequest,
|
|
||||||
) -> Result<TableDefinitionResponse, Status> {
|
|
||||||
// Create owned copies of the strings after validation
|
|
||||||
let profile_name = {
|
|
||||||
let trimmed = request.profile_name.trim();
|
|
||||||
validate_identifier_format(trimmed, "Profile name")?;
|
|
||||||
trimmed.to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add validation to prevent reserved schemas
|
|
||||||
if is_reserved_schema(&profile_name) {
|
|
||||||
return Err(Status::invalid_argument("Profile name is reserved and cannot be used"));
|
|
||||||
}
|
|
||||||
|
|
||||||
const MAX_IDENTIFIER_LENGTH: usize = 63;
|
|
||||||
|
|
||||||
if profile_name.len() > MAX_IDENTIFIER_LENGTH {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"Profile name '{}' exceeds the {} character limit.",
|
|
||||||
profile_name,
|
|
||||||
MAX_IDENTIFIER_LENGTH
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
let table_name = {
|
|
||||||
let trimmed = request.table_name.trim();
|
|
||||||
validate_identifier_format(trimmed, "Table name")?;
|
|
||||||
|
|
||||||
if trimmed.len() > MAX_IDENTIFIER_LENGTH {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"Table name '{}' exceeds the {} character limit.",
|
|
||||||
trimmed,
|
|
||||||
MAX_IDENTIFIER_LENGTH
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check invalid table names on the original input
|
|
||||||
if is_invalid_table_name(trimmed) {
|
|
||||||
return Err(Status::invalid_argument(
|
|
||||||
"Table name cannot be 'id', 'deleted', 'created_at' or end with '_id'"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
trimmed.to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut tx = db_pool.begin().await
|
|
||||||
.map_err(|e| Status::internal(format!("Failed to start transaction: {}", e)))?;
|
|
||||||
|
|
||||||
match execute_table_definition(&mut tx, request, table_name, profile_name).await {
|
|
||||||
Ok(response) => {
|
|
||||||
tx.commit().await
|
|
||||||
.map_err(|e| Status::internal(format!("Failed to commit transaction: {}", e)))?;
|
|
||||||
Ok(response)
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
let _ = tx.rollback().await;
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_table_definition(
|
|
||||||
tx: &mut Transaction<'_, Postgres>,
|
|
||||||
mut request: PostTableDefinitionRequest,
|
|
||||||
table_name: String,
|
|
||||||
profile_name: String,
|
|
||||||
) -> Result<TableDefinitionResponse, Status> {
|
|
||||||
// Use the validated profile_name for schema insertion
|
|
||||||
let schema = sqlx::query!(
|
|
||||||
"INSERT INTO schemas (name) VALUES ($1)
|
|
||||||
ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name
|
|
||||||
RETURNING id",
|
|
||||||
profile_name // Use the validated profile name
|
|
||||||
)
|
|
||||||
.fetch_one(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Schema error: {}", e)))?;
|
|
||||||
|
|
||||||
// Create PostgreSQL schema if it doesn't exist
|
|
||||||
let create_schema_sql = format!("CREATE SCHEMA IF NOT EXISTS \"{}\"", profile_name);
|
|
||||||
sqlx::query(&create_schema_sql)
|
|
||||||
.execute(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Schema creation failed: {}", e)))?;
|
|
||||||
|
|
||||||
let mut links = Vec::new();
|
|
||||||
let mut seen_tables = std::collections::HashSet::new();
|
|
||||||
|
|
||||||
for link in request.links.drain(..) {
|
|
||||||
// Check for duplicate link
|
|
||||||
if !seen_tables.insert(link.linked_table_name.clone()) {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"Duplicate link to table '{}'",
|
|
||||||
link.linked_table_name
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
let linked_table = sqlx::query!(
|
|
||||||
"SELECT id FROM table_definitions
|
|
||||||
WHERE schema_id = $1 AND table_name = $2",
|
|
||||||
schema.id,
|
|
||||||
link.linked_table_name
|
|
||||||
)
|
|
||||||
.fetch_optional(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Linked table lookup failed: {}", e)))?;
|
|
||||||
|
|
||||||
let linked_id = linked_table.ok_or_else(||
|
|
||||||
Status::not_found(format!("Linked table {} not found", link.linked_table_name))
|
|
||||||
)?.id;
|
|
||||||
|
|
||||||
links.push((linked_id, link.required));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut stored_columns = Vec::new();
|
|
||||||
let mut sql_columns = Vec::new();
|
|
||||||
|
|
||||||
for col_def in request.columns.drain(..) {
|
|
||||||
let col_name = col_def.name.trim().to_string();
|
|
||||||
validate_identifier_format(&col_name, "Column name")?;
|
|
||||||
|
|
||||||
if col_name.ends_with("_id") || col_name == "id" || col_name == "deleted" || col_name == "created_at" {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"Column name '{}' cannot be 'id', 'deleted', 'created_at' or end with '_id'",
|
|
||||||
col_name
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
let sql_type = map_field_type(&col_def.field_type)?;
|
|
||||||
sql_columns.push(format!("\"{}\" {}", col_name, sql_type));
|
|
||||||
|
|
||||||
// push the proto type (serde serializable)
|
|
||||||
stored_columns.push(ColumnDefinition {
|
|
||||||
name: col_name,
|
|
||||||
field_type: col_def.field_type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Indexes
|
|
||||||
let mut stored_indexes = Vec::new();
|
|
||||||
let mut indexes = Vec::new();
|
|
||||||
for idx in request.indexes.drain(..) {
|
|
||||||
let idx_name = idx.trim().to_string();
|
|
||||||
validate_identifier_format(&idx_name, "Index name")?;
|
|
||||||
|
|
||||||
if !sql_columns.iter().any(|c| c.starts_with(&format!("\"{}\"", idx_name))) {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"Index column '{}' not found", idx_name
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
stored_indexes.push(idx_name.clone());
|
|
||||||
indexes.push(idx_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (create_sql, index_sql) = generate_table_sql(tx, &profile_name, &table_name, &sql_columns, &indexes, &links).await?;
|
|
||||||
|
|
||||||
// Use schema_id instead of profile_id
|
|
||||||
let table_def = sqlx::query!(
|
|
||||||
r#"INSERT INTO table_definitions
|
|
||||||
(schema_id, table_name, columns, indexes)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING id"#,
|
|
||||||
schema.id,
|
|
||||||
&table_name,
|
|
||||||
serde_json::to_value(&stored_columns).unwrap(),
|
|
||||||
serde_json::to_value(&stored_indexes).unwrap()
|
|
||||||
)
|
|
||||||
.fetch_one(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
if let Some(db_err) = e.as_database_error() {
|
|
||||||
// Update constraint name to match new schema
|
|
||||||
if db_err.constraint() == Some("idx_table_definitions_schema_table") {
|
|
||||||
return Status::already_exists("Table already exists in this profile");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Status::internal(format!("Database error: {}", e))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
for col_def in &sql_columns {
|
|
||||||
// Column string looks like "\"name\" TYPE", split out identifier
|
|
||||||
let col_name = col_def.split_whitespace().next().unwrap_or("");
|
|
||||||
let clean_col = col_name.trim_matches('"');
|
|
||||||
|
|
||||||
// Default empty config — currently only character_limits block, none set.
|
|
||||||
let default_cfg = serde_json::json!({
|
|
||||||
"character_limits": { "min": 0, "max": 0, "warn_at": null, "count_mode": "CHARS" }
|
|
||||||
});
|
|
||||||
|
|
||||||
sqlx::query!(
|
|
||||||
r#"INSERT INTO table_validation_rules (table_def_id, data_key, config)
|
|
||||||
VALUES ($1, $2, $3)
|
|
||||||
ON CONFLICT (table_def_id, data_key) DO NOTHING"#,
|
|
||||||
table_def.id,
|
|
||||||
clean_col,
|
|
||||||
default_cfg
|
|
||||||
)
|
|
||||||
.execute(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Failed to insert default validation rule for column {}: {}", clean_col, e)))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (linked_id, is_required) in links {
|
|
||||||
sqlx::query!(
|
|
||||||
"INSERT INTO table_definition_links
|
|
||||||
(source_table_id, linked_table_id, is_required)
|
|
||||||
VALUES ($1, $2, $3)",
|
|
||||||
table_def.id,
|
|
||||||
linked_id,
|
|
||||||
is_required
|
|
||||||
)
|
|
||||||
.execute(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Failed to save link: {}", e)))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlx::query(&create_sql)
|
|
||||||
.execute(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Table creation failed: {}", e)))?;
|
|
||||||
|
|
||||||
for sql in &index_sql {
|
|
||||||
sqlx::query(sql)
|
|
||||||
.execute(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Index creation failed: {}", e)))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(TableDefinitionResponse {
|
|
||||||
success: true,
|
|
||||||
sql: format!("{}\n{}", create_sql, index_sql.join("\n")),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate_table_sql(
|
|
||||||
tx: &mut Transaction<'_, Postgres>,
|
|
||||||
profile_name: &str,
|
|
||||||
table_name: &str,
|
|
||||||
columns: &[String],
|
|
||||||
indexes: &[String],
|
|
||||||
links: &[(i64, bool)],
|
|
||||||
) -> Result<(String, Vec<String>), Status> {
|
|
||||||
let qualified_table = format!("\"{}\".\"{}\"", profile_name, table_name);
|
|
||||||
let mut system_columns = vec![
|
|
||||||
"id BIGSERIAL PRIMARY KEY".to_string(),
|
|
||||||
"deleted BOOLEAN NOT NULL DEFAULT FALSE".to_string(),
|
|
||||||
];
|
|
||||||
|
|
||||||
for (linked_id, required) in links {
|
|
||||||
let linked_table = get_table_name_by_id(tx, *linked_id).await?;
|
|
||||||
let qualified_linked_table = format!("\"{}\".\"{}\"", profile_name, linked_table);
|
|
||||||
|
|
||||||
// Simply use the full table name - no truncation!
|
|
||||||
let null_clause = if *required { "NOT NULL" } else { "" };
|
|
||||||
system_columns.push(
|
|
||||||
format!("\"{}_id\" BIGINT {} REFERENCES {}(id)",
|
|
||||||
linked_table, null_clause, qualified_linked_table
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let all_columns = system_columns
|
|
||||||
.iter()
|
|
||||||
.chain(columns.iter())
|
|
||||||
.cloned()
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let create_sql = format!(
|
|
||||||
"CREATE TABLE {} (\n {},\n created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP\n)",
|
|
||||||
qualified_table,
|
|
||||||
all_columns.join(",\n ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut all_indexes = Vec::new();
|
|
||||||
for (linked_id, _) in links {
|
|
||||||
let linked_table = get_table_name_by_id(tx, *linked_id).await?;
|
|
||||||
all_indexes.push(format!(
|
|
||||||
"CREATE INDEX \"idx_{}_{}_fk\" ON {} (\"{}_id\")",
|
|
||||||
table_name, linked_table, qualified_table, linked_table
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
for idx in indexes {
|
|
||||||
all_indexes.push(format!(
|
|
||||||
"CREATE INDEX \"idx_{}_{}\" ON {} (\"{}\")",
|
|
||||||
table_name, idx, qualified_table, idx
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok((create_sql, all_indexes))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_table_name_by_id(
|
|
||||||
tx: &mut Transaction<'_, Postgres>,
|
|
||||||
table_id: i64,
|
|
||||||
) -> Result<String, Status> {
|
|
||||||
let record = sqlx::query!(
|
|
||||||
"SELECT table_name FROM table_definitions WHERE id = $1",
|
|
||||||
table_id
|
|
||||||
)
|
|
||||||
.fetch_one(&mut **tx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(format!("Table lookup failed: {}", e)))?;
|
|
||||||
|
|
||||||
Ok(record.table_name)
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// src/table_definition/mod.rs
|
|
||||||
|
|
||||||
pub mod models;
|
|
||||||
pub mod handlers;
|
|
||||||
pub mod repo;
|
|
||||||
|
|
||||||
pub use repo::*;
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
// src/table_definition/models.rs
|
|
||||||
use tonic::Status;
|
|
||||||
|
|
||||||
/// Predefined static field mappings
|
|
||||||
// TODO CRITICAL add decimal with optional precision"
|
|
||||||
pub const PREDEFINED_FIELD_TYPES: &[(&str, &str)] = &[
|
|
||||||
("text", "TEXT"),
|
|
||||||
("string", "TEXT"),
|
|
||||||
("boolean", "BOOLEAN"),
|
|
||||||
("timestamp", "TIMESTAMPTZ"),
|
|
||||||
("timestamptz", "TIMESTAMPTZ"),
|
|
||||||
("time", "TIMESTAMPTZ"),
|
|
||||||
("money", "NUMERIC(14, 4)"),
|
|
||||||
("integer", "INTEGER"),
|
|
||||||
("int", "INTEGER"),
|
|
||||||
("biginteger", "BIGINT"),
|
|
||||||
("bigint", "BIGINT"),
|
|
||||||
("date", "DATE"),
|
|
||||||
];
|
|
||||||
|
|
||||||
/// reusable decimal number validation
|
|
||||||
pub fn validate_decimal_number_format(num_str: &str, param_name: &str) -> Result<(), Status> {
|
|
||||||
if num_str.is_empty() {
|
|
||||||
return Err(Status::invalid_argument(format!("{} cannot be empty", param_name)));
|
|
||||||
}
|
|
||||||
if num_str.starts_with('+') || num_str.starts_with('-') {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"{} cannot have explicit positive/negative signs", param_name
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
if num_str.contains('.') {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"{} must be a whole number (no decimal point)", param_name
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
if num_str.len() > 1 && num_str.starts_with('0') {
|
|
||||||
let trimmed = num_str.trim_start_matches('0');
|
|
||||||
let suggestion = if trimmed.is_empty() { "0" } else { trimmed };
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"{} cannot have leading zeros (use '{}' instead of '{}')",
|
|
||||||
param_name, suggestion, num_str
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
if !num_str.chars().all(|c| c.is_ascii_digit()) {
|
|
||||||
return Err(Status::invalid_argument(format!(
|
|
||||||
"{} contains invalid characters. Only digits allowed", param_name
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// reusable field type mapper
|
|
||||||
pub fn map_field_type(field_type: &str) -> Result<String, Status> {
|
|
||||||
let lower_field_type = field_type.to_lowercase();
|
|
||||||
|
|
||||||
if lower_field_type.starts_with("decimal(") && lower_field_type.ends_with(')') {
|
|
||||||
let args = lower_field_type.strip_prefix("decimal(").unwrap()
|
|
||||||
.strip_suffix(')').unwrap();
|
|
||||||
|
|
||||||
if let Some((p_str, s_str)) = args.split_once(',') {
|
|
||||||
let precision_str = p_str.trim();
|
|
||||||
let scale_str = s_str.trim();
|
|
||||||
|
|
||||||
validate_decimal_number_format(precision_str, "precision")?;
|
|
||||||
validate_decimal_number_format(scale_str, "scale")?;
|
|
||||||
|
|
||||||
let precision = precision_str.parse::<u32>()
|
|
||||||
.map_err(|_| Status::invalid_argument("Invalid precision"))?;
|
|
||||||
let scale = scale_str.parse::<u32>()
|
|
||||||
.map_err(|_| Status::invalid_argument("Invalid scale"))?;
|
|
||||||
|
|
||||||
if precision < 1 {
|
|
||||||
return Err(Status::invalid_argument("Precision must be >= 1"));
|
|
||||||
}
|
|
||||||
if scale > precision {
|
|
||||||
return Err(Status::invalid_argument("Scale cannot be > precision"));
|
|
||||||
}
|
|
||||||
return Ok(format!("NUMERIC({}, {})", precision, scale));
|
|
||||||
} else {
|
|
||||||
return Err(Status::invalid_argument(
|
|
||||||
"Invalid decimal format. Expected decimal(precision, scale)"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PREDEFINED_FIELD_TYPES
|
|
||||||
.iter()
|
|
||||||
.find(|(key, _)| *key == lower_field_type.as_str())
|
|
||||||
.map(|(_, sql_type)| sql_type.to_string())
|
|
||||||
.ok_or_else(|| Status::invalid_argument(format!("Invalid field type: {}", field_type)))
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// src/table_definition/repo.rs
|
|
||||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub struct TableDefRow {
|
|
||||||
pub id: i64,
|
|
||||||
pub table_name: String,
|
|
||||||
pub columns: Vec<ColumnDefinition>,
|
|
||||||
pub indexes: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_table_definition(
|
|
||||||
db: &PgPool,
|
|
||||||
id: i64,
|
|
||||||
) -> Result<TableDefRow, anyhow::Error> {
|
|
||||||
let rec = sqlx::query!(
|
|
||||||
r#"
|
|
||||||
SELECT id, table_name, columns, indexes
|
|
||||||
FROM table_definitions
|
|
||||||
WHERE id = $1
|
|
||||||
"#,
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(db)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(TableDefRow {
|
|
||||||
id: rec.id,
|
|
||||||
table_name: rec.table_name,
|
|
||||||
columns: serde_json::from_value(rec.columns)?, // 🔑
|
|
||||||
indexes: serde_json::from_value(rec.indexes)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user