DATA MODULE OCAML "some-module"
TABLE test_table {
id INT PRIMARY KEY,
some_text TEXT DEFAULT 'hello',
}
open! Context
open! Db_types
let define_data () =
mk_test_table ~id:123 () |> def_test_table;
mk_test_table ~id:123 ~some_text:"overriden" () |> def_test_table;
()
TABLE server {
hostname TEXT PRIMARY KEY,
}
TABLE server_volume {
volume_name TEXT PRIMARY KEY CHILD OF server,
mountpoint TEXT,
}
DATA server(hostname) {
server-a WITH server_volume {
pgtest1, '/srv/volumes/pgtest1';
};
server-b WITH server_volume {
pgtest1, '/srv/volumes/pgtest1';
};
}
TABLE db_deployment {
deployment_name TEXT PRIMARY KEY,
}
TABLE db_deployment_instance {
deployment_id INT PRIMARY KEY CHILD OF db_deployment,
db_server REF FOREIGN CHILD server_volume,
CHECK { deployment_id > 0 },
}
DATA STRUCT db_deployment [
{
deployment_name: foo WITH db_deployment_instance [
{
deployment_id: 1,
db_server: server-a=>pgtest1,
},
{
deployment_id: 2,
db_server: server-b=>pgtest1,
},
]
}
]
TABLE server {
hostname TEXT PRIMARY KEY,
ssh_interface REF CHILD network_interface,
}
TABLE network {
network_name TEXT PRIMARY KEY,
cidr TEXT,
}
TABLE network_interface {
if_name TEXT PRIMARY KEY CHILD OF server,
if_network REF network,
if_ip TEXT,
if_subnet_mask_cidr INT,
}
DATA STRUCT network [
{
network_name: lan,
cidr: '10.16.0.0/12',
}
]
DATA server(hostname, ssh_interface) {
server-a, eth0 WITH network_interface {
eth0, lan, 10.17.0.10, 24;
};
}
TABLE existant_parent {
some_key TEXT PRIMARY KEY,
spec_child REF CHILD existant_child_2,
}
TABLE existant_child {
some_child_key TEXT PRIMARY KEY CHILD OF existant_parent,
}
TABLE existant_child_2 {
some_child_key_2 TEXT PRIMARY KEY CHILD OF existant_child,
}
DATA existant_parent {
outer_val, inner_val=>henloz WITH existant_child {
inner_val WITH existant_child_2 {
henlo
}
}
}
TABLE server {
hostname TEXT PRIMARY KEY,
tld REF tld DETACHED DEFAULT,
fqdn TEXT GENERATED AS { hostname .. "." .. tld },
}
TABLE tld {
domain TEXT PRIMARY KEY,
}
DEFAULTS {
// defines default for table 'server' and column 'tld'.
// you cannot define defaults for non existing tables
// and column must be marked as detached default
server.tld epl-infra.net,
}
// now we can define data with detached default
DATA STRUCT server {
hostname: server-a
}
DATA tld {
epl-infra.net;
}
| application | monitoring | database access | queues | logging | proxying | load balancing | .. | feature 1000th |
|-------------+------------+-----------------+--------+---------+----------+----------------+----+----------------|
| app 1 | | | | | | | | |
| app 2 | | | | | | | | |
| app 3 | | | | | | | | |
| ... | | | | | | | | |
| app 1000th | | | | | | | | |
TABLE server {
hostname TEXT PRIMARY KEY,
}
TABLE reserved_port {
number INT PRIMARY KEY CHILD OF server,
}
TABLE docker_container {
name TEXT PRIMARY KEY CHILD OF server,
}
TABLE docker_container_port {
port_name TEXT PRIMARY KEY CHILD OF docker_container,
reserved_port REF reserved_port,
}
DATA server {
epyc-1
}
DATA STRUCT docker_container {
hostname: epyc-1,
name: postgres
WITH docker_container_port {
port_name: main_port,
reserved_port: 5432
}
}
NonExistingForeignKey { table_with_foreign_key: "docker_container_port", foreign_key_column: "reserved_port", referred_table: "reserved_port", referred_table_column: "number", key_value: "5432" }
DATA reserved_port {
epyc-1, 5432
}
FoundDuplicateChildPrimaryKeySet { table_name: "reserved_port", columns: "(hostname, number)", duplicate_values: "(epyc-1, 5432)" }
INCLUDE LUA {
data('reserved_port', { hostname = 'epyc-1', number = 5432 })
}
__do_not_refer_to_this_internal_value_in_your_code_dumbo__ = {}
function data(targetTable, newRow)
local queue = __do_not_refer_to_this_internal_value_in_your_code_dumbo__
if queue[targetTable] == nil then
queue[targetTable] = {}
end
-- we simply accumulate values to insert in lua runtime and then process
-- them in one go in rust
table.insert(queue[targetTable], newRow)
end
INCLUDE LUA {
function docker_container(hostname, containerName, portName, portValue)
data('docker_container', {
hostname = hostname,
name = containerName,
})
data('docker_container_port', {
hostname = hostname,
name = containerName,
port_name = portName,
reserved_port = portValue
})
data('reserved_port', {
hostname = hostname,
number = portValue,
})
end
}
INCLUDE LUA {
docker_container('epyc-1', 'postgres', 'main_port', 5432)
}
INCLUDE LUA "lib.lua"