init
This commit is contained in:
commit
59d81cb4d7
BIN
_build/.db
Normal file
BIN
_build/.db
Normal file
Binary file not shown.
BIN
_build/.digest-db
Normal file
BIN
_build/.digest-db
Normal file
Binary file not shown.
1
_build/.filesystem-clock
Normal file
1
_build/.filesystem-clock
Normal file
@ -0,0 +1 @@
|
|||||||
|
<dummy>
|
0
_build/.lock
Normal file
0
_build/.lock
Normal file
1
_build/.sandbox/.hg/requires
Normal file
1
_build/.sandbox/.hg/requires
Normal file
@ -0,0 +1 @@
|
|||||||
|
Escaping the Dune sandbox
|
2
_build/default/.dune/configurator
Normal file
2
_build/default/.dune/configurator
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(ocamlc /usr/bin/ocamlc.opt)
|
||||||
|
(ocaml_config_vars (afl_instrument false) (architecture amd64) (asm x86_64-linux-gnu-as) (asm_cfi_supported true) (ast_impl_magic_number Caml1999M030) (ast_intf_magic_number Caml1999N030) (bytecomp_c_compiler "x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (bytecomp_c_libraries "-lm -lpthread") (c_compiler x86_64-linux-gnu-gcc) (ccomp_type cc) (cma_magic_number Caml1999A030) (cmi_magic_number Caml1999I030) (cmo_magic_number Caml1999O030) (cmt_magic_number Caml1999T030) (cmx_magic_number Caml1999Y030) (cmxa_magic_number Caml1999Z030) (cmxs_magic_number Caml1999D030) (default_executable_name a.out) (default_safe_string true) (exec_magic_number Caml1999X030) (ext_asm .s) (ext_dll .so) (ext_exe "") (ext_lib .a) (ext_obj .o) (flambda false) (flat_float_array true) (function_sections true) (host x86_64-pc-linux-gnu) (int_size 63) (linear_magic_number Caml1999L030) (model default) (native_c_compiler "x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (native_c_libraries "-lm ") (native_pack_linker "x86_64-linux-gnu-ld -r -o ") (ocamlc_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security") (ocamlc_cppflags "-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (ocamlopt_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security") (ocamlopt_cppflags "-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (os_type Unix) (ranlib x86_64-linux-gnu-ranlib) (safe_string true) (standard_library /usr/lib/ocaml) (standard_library_default /usr/lib/ocaml) (supports_shared_libraries true) (system linux) (systhread_supported true) (target x86_64-pc-linux-gnu) (version 4.13.1) (windows_unicode false) (with_frame_pointers false) (word_size 64))
|
1
_build/default/.dune/configurator.v2
Normal file
1
_build/default/.dune/configurator.v2
Normal file
@ -0,0 +1 @@
|
|||||||
|
((6:ocamlc19:/usr/bin/ocamlc.opt)(17:ocaml_config_vars((14:afl_instrument5:false)(12:architecture5:amd64)(3:asm19:x86_64-linux-gnu-as)(17:asm_cfi_supported4:true)(21:ast_impl_magic_number12:Caml1999M030)(21:ast_intf_magic_number12:Caml1999N030)(19:bytecomp_c_compiler241:x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(20:bytecomp_c_libraries14:-lm -lpthread)(10:c_compiler20:x86_64-linux-gnu-gcc)(10:ccomp_type2:cc)(16:cma_magic_number12:Caml1999A030)(16:cmi_magic_number12:Caml1999I030)(16:cmo_magic_number12:Caml1999O030)(16:cmt_magic_number12:Caml1999T030)(16:cmx_magic_number12:Caml1999Y030)(17:cmxa_magic_number12:Caml1999Z030)(17:cmxs_magic_number12:Caml1999D030)(23:default_executable_name5:a.out)(19:default_safe_string4:true)(17:exec_magic_number12:Caml1999X030)(7:ext_asm2:.s)(7:ext_dll3:.so)(7:ext_exe0:)(7:ext_lib2:.a)(7:ext_obj2:.o)(7:flambda5:false)(16:flat_float_array4:true)(17:function_sections4:true)(4:host19:x86_64-pc-linux-gnu)(8:int_size2:63)(19:linear_magic_number12:Caml1999L030)(5:model7:default)(17:native_c_compiler241:x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(18:native_c_libraries4:-lm )(18:native_pack_linker26:x86_64-linux-gnu-ld -r -o )(13:ocamlc_cflags165:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security)(15:ocamlc_cppflags54:-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(15:ocamlopt_cflags165:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security)(17:ocamlopt_cppflags54:-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(7:os_type4:Unix)(6:ranlib23:x86_64-linux-gnu-ranlib)(11:safe_string4:true)(16:standard_library14:/usr/lib/ocaml)(24:standard_library_default14:/usr/lib/ocaml)(25:supports_shared_libraries4:true)(6:system5:linux)(19:systhread_supported4:true)(6:target19:x86_64-pc-linux-gnu)(7:version6:4.13.1)(15:windows_unicode5:false)(19:with_frame_pointers5:false)(9:word_size2:64))))
|
@ -0,0 +1 @@
|
|||||||
|
let () = Ppxlib.Driver.standalone ()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
_build/default/.ppx/e047dd045732eb45a5c5aa4a3855a525/ppx.exe
Executable file
BIN
_build/default/.ppx/e047dd045732eb45a5c5aa4a3855a525/ppx.exe
Executable file
Binary file not shown.
0
_build/default/META.metadata_store
Normal file
0
_build/default/META.metadata_store
Normal file
BIN
_build/default/bin/.merlin-conf/exe-main
Normal file
BIN
_build/default/bin/.merlin-conf/exe-main
Normal file
Binary file not shown.
4
_build/default/bin/main.ml
Normal file
4
_build/default/bin/main.ml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
open Metadata_store
|
||||||
|
|
||||||
|
(* Example usage *)
|
||||||
|
let () = init_db "host=localhost dbname=metastore user=youruser password=yourpassword"
|
1
_build/default/bin/main.mli
Normal file
1
_build/default/bin/main.mli
Normal file
@ -0,0 +1 @@
|
|||||||
|
(* Auto-generated by Dune *)
|
BIN
_build/default/lib/.merlin-conf/lib-metadata_store
Normal file
BIN
_build/default/lib/.merlin-conf/lib-metadata_store
Normal file
Binary file not shown.
BIN
_build/default/lib/.metadata_store.objs/byte/metadata_store.cmi
Normal file
BIN
_build/default/lib/.metadata_store.objs/byte/metadata_store.cmi
Normal file
Binary file not shown.
BIN
_build/default/lib/.metadata_store.objs/byte/metadata_store.cmo
Normal file
BIN
_build/default/lib/.metadata_store.objs/byte/metadata_store.cmo
Normal file
Binary file not shown.
BIN
_build/default/lib/.metadata_store.objs/byte/metadata_store.cmt
Normal file
BIN
_build/default/lib/.metadata_store.objs/byte/metadata_store.cmt
Normal file
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
lib/init.pp.ml: List PGOCaml Printf
|
Binary file not shown.
BIN
_build/default/lib/.metadata_store.objs/native/metadata_store.o
Normal file
BIN
_build/default/lib/.metadata_store.objs/native/metadata_store.o
Normal file
Binary file not shown.
99
_build/default/lib/init.ml
Normal file
99
_build/default/lib/init.ml
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
let () =
|
||||||
|
let dbh = PGOCaml.connect () in
|
||||||
|
(* Define DDL statements for each table *)
|
||||||
|
let ddl_statements = [
|
||||||
|
"CREATE TABLE IF NOT EXISTS Databases (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Schemas (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
database_id INT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (database_id) REFERENCES Databases (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Tables (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
schema_id INT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
is_partitioned BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (schema_id) REFERENCES Schemas (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Columns (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
table_id INT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
data_type VARCHAR(50) NOT NULL,
|
||||||
|
is_nullable BOOLEAN DEFAULT TRUE,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (table_id) REFERENCES Tables (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Partitions (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
table_id INT NOT NULL,
|
||||||
|
partition_key VARCHAR(255) NOT NULL,
|
||||||
|
partition_value VARCHAR(255) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (table_id) REFERENCES Tables (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Users (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
username VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
email VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
role VARCHAR(50) DEFAULT 'user',
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Permissions (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INT NOT NULL,
|
||||||
|
resource_type VARCHAR(50) NOT NULL,
|
||||||
|
resource_id INT NOT NULL,
|
||||||
|
access_type VARCHAR(50) NOT NULL,
|
||||||
|
granted_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES Users (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
] in
|
||||||
|
|
||||||
|
(* Execute each DDL statement *)
|
||||||
|
let execute_ddl dbh ddl =
|
||||||
|
[%pgsql dbh "execute" "CREATE TABLE IF NOT EXISTS Databases (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)"]
|
||||||
|
in
|
||||||
|
|
||||||
|
let () =
|
||||||
|
try
|
||||||
|
List.iter (execute_ddl dbh) ddl_statements;
|
||||||
|
Printf.printf "Database initialized successfully.\n"
|
||||||
|
with
|
||||||
|
| PGOCaml.Error err ->
|
||||||
|
Printf.eprintf "Error initializing database: %s\n" (PGOCaml.string_of_error err)
|
||||||
|
| exn ->
|
||||||
|
Printf.eprintf "Unexpected error: %s\n" (Printexc.to_string exn)
|
||||||
|
in
|
||||||
|
|
||||||
|
(* Close the connection *)
|
||||||
|
PGOCaml.close dbh
|
||||||
|
|
4
_build/default/lib/metadata_store.ml-gen
Normal file
4
_build/default/lib/metadata_store.ml-gen
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(* generated by dune *)
|
||||||
|
|
||||||
|
(** @canonical Metadata_store.Init *)
|
||||||
|
module Init = Metadata_store__Init
|
4
_build/default/metadata_store.dune-package
Normal file
4
_build/default/metadata_store.dune-package
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(lang dune 3.16)
|
||||||
|
(name metadata_store)
|
||||||
|
(sections (lib .) (bin ../../bin))
|
||||||
|
(files (lib (META dune-package opam)) (bin (metadata_store)))
|
31
_build/default/metadata_store.opam
Normal file
31
_build/default/metadata_store.opam
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# This file is generated by dune, edit dune-project instead
|
||||||
|
opam-version: "2.0"
|
||||||
|
synopsis: "A short synopsis"
|
||||||
|
description: "A longer description"
|
||||||
|
maintainer: ["Maintainer Name"]
|
||||||
|
authors: ["Author Name"]
|
||||||
|
license: "LICENSE"
|
||||||
|
tags: ["topics" "to describe" "your" "project"]
|
||||||
|
homepage: "https://github.com/username/reponame"
|
||||||
|
doc: "https://url/to/documentation"
|
||||||
|
bug-reports: "https://github.com/username/reponame/issues"
|
||||||
|
depends: [
|
||||||
|
"ocaml"
|
||||||
|
"dune" {>= "3.16"}
|
||||||
|
"odoc" {with-doc}
|
||||||
|
]
|
||||||
|
build: [
|
||||||
|
["dune" "subst"] {dev}
|
||||||
|
[
|
||||||
|
"dune"
|
||||||
|
"build"
|
||||||
|
"-p"
|
||||||
|
name
|
||||||
|
"-j"
|
||||||
|
jobs
|
||||||
|
"@install"
|
||||||
|
"@runtest" {with-test}
|
||||||
|
"@doc" {with-doc}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
dev-repo: "git+https://github.com/username/reponame.git"
|
BIN
_build/default/test/.merlin-conf/exe-test_metadata_store
Normal file
BIN
_build/default/test/.merlin-conf/exe-test_metadata_store
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
_build/default/test/test_metadata_store.exe
Executable file
BIN
_build/default/test/test_metadata_store.exe
Executable file
Binary file not shown.
0
_build/default/test/test_metadata_store.ml
Normal file
0
_build/default/test/test_metadata_store.ml
Normal file
1
_build/default/test/test_metadata_store.mli
Normal file
1
_build/default/test/test_metadata_store.mli
Normal file
@ -0,0 +1 @@
|
|||||||
|
(* Auto-generated by Dune *)
|
1
_build/install/default/lib/metadata_store/META
Symbolic link
1
_build/install/default/lib/metadata_store/META
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../../default/META.metadata_store
|
1
_build/install/default/lib/metadata_store/dune-package
Symbolic link
1
_build/install/default/lib/metadata_store/dune-package
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../../default/metadata_store.dune-package
|
1
_build/install/default/lib/metadata_store/opam
Symbolic link
1
_build/install/default/lib/metadata_store/opam
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../../default/metadata_store.opam
|
27
_build/log
Normal file
27
_build/log
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# dune build
|
||||||
|
# OCAMLPARAM: unset
|
||||||
|
# Shared cache: disabled
|
||||||
|
# Shared cache location: /home/simon/.cache/dune/db
|
||||||
|
# Workspace root: /home/simon/Documents/metadata_store
|
||||||
|
# Auto-detected concurrency: 4
|
||||||
|
# Dune context:
|
||||||
|
# { name = "default"
|
||||||
|
# ; kind = "default"
|
||||||
|
# ; profile = Dev
|
||||||
|
# ; merlin = true
|
||||||
|
# ; fdo_target_exe = None
|
||||||
|
# ; build_dir = In_build_dir "default"
|
||||||
|
# ; instrument_with = []
|
||||||
|
# }
|
||||||
|
$ /usr/bin/ocamlc.opt -config > /tmp/dune_45b47b_output
|
||||||
|
$ (cd _build/.sandbox/0ad8d6c85f98cad7a074d690c83848a3/default && .ppx/e047dd045732eb45a5c5aa4a3855a525/ppx.exe --cookie 'library-name="metadata_store"' -o lib/init.pp.ml --impl lib/init.ml -corrected-suffix .ppx-corrected -diff-cmd - -dump-ast)
|
||||||
|
> File "lib/init.ml", lines 77-83, characters 4-7:
|
||||||
|
> 77 | ....[%pgsql dbh "execute" "CREATE TABLE IF NOT EXISTS Databases (
|
||||||
|
> 78 | id SERIAL PRIMARY KEY,
|
||||||
|
> 79 | name VARCHAR(255) NOT NULL,
|
||||||
|
> 80 | description TEXT,
|
||||||
|
> 81 | created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
> 82 | updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
> 83 | )"]
|
||||||
|
> Error: PG'OCaml PPX error: Could not make the connection host=unix, port=5432, user=simon, password=*****, database=simon, error: PGOCaml_generic.Make(Thread).Error("PGOCaml: Could not connect to database")
|
||||||
|
[1]
|
4
bin/dune
Normal file
4
bin/dune
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(executable
|
||||||
|
(public_name metadata_store)
|
||||||
|
(name main)
|
||||||
|
(libraries metadata_store))
|
4
bin/main.ml
Normal file
4
bin/main.ml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
open Metadata_store
|
||||||
|
|
||||||
|
(* Example usage *)
|
||||||
|
let () = init_db "host=localhost dbname=metastore user=youruser password=yourpassword"
|
26
dune-project
Normal file
26
dune-project
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
(lang dune 3.16)
|
||||||
|
|
||||||
|
(name metadata_store)
|
||||||
|
|
||||||
|
(generate_opam_files true)
|
||||||
|
|
||||||
|
(source
|
||||||
|
(github username/reponame))
|
||||||
|
|
||||||
|
(authors "Author Name")
|
||||||
|
|
||||||
|
(maintainers "Maintainer Name")
|
||||||
|
|
||||||
|
(license LICENSE)
|
||||||
|
|
||||||
|
(documentation https://url/to/documentation)
|
||||||
|
|
||||||
|
(package
|
||||||
|
(name metadata_store)
|
||||||
|
(synopsis "A short synopsis")
|
||||||
|
(description "A longer description")
|
||||||
|
(depends ocaml dune)
|
||||||
|
(tags
|
||||||
|
(topics "to describe" your project)))
|
||||||
|
|
||||||
|
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html
|
5
lib/dune
Normal file
5
lib/dune
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(library
|
||||||
|
(modules init)
|
||||||
|
(libraries pgocaml pgocaml_ppx)
|
||||||
|
(preprocess (pps pgocaml_ppx))
|
||||||
|
(name metadata_store))
|
99
lib/init.ml
Normal file
99
lib/init.ml
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
let () =
|
||||||
|
let dbh = PGOCaml.connect () in
|
||||||
|
(* Define DDL statements for each table *)
|
||||||
|
let ddl_statements = [
|
||||||
|
"CREATE TABLE IF NOT EXISTS Databases (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Schemas (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
database_id INT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (database_id) REFERENCES Databases (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Tables (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
schema_id INT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
is_partitioned BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (schema_id) REFERENCES Schemas (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Columns (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
table_id INT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
data_type VARCHAR(50) NOT NULL,
|
||||||
|
is_nullable BOOLEAN DEFAULT TRUE,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (table_id) REFERENCES Tables (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Partitions (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
table_id INT NOT NULL,
|
||||||
|
partition_key VARCHAR(255) NOT NULL,
|
||||||
|
partition_value VARCHAR(255) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (table_id) REFERENCES Tables (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Users (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
username VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
email VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
role VARCHAR(50) DEFAULT 'user',
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)";
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS Permissions (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INT NOT NULL,
|
||||||
|
resource_type VARCHAR(50) NOT NULL,
|
||||||
|
resource_id INT NOT NULL,
|
||||||
|
access_type VARCHAR(50) NOT NULL,
|
||||||
|
granted_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES Users (id) ON DELETE CASCADE
|
||||||
|
)";
|
||||||
|
] in
|
||||||
|
|
||||||
|
(* Execute each DDL statement *)
|
||||||
|
let execute_ddl dbh ddl =
|
||||||
|
[%pgsql dbh "execute" "CREATE TABLE IF NOT EXISTS Databases (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)"]
|
||||||
|
in
|
||||||
|
|
||||||
|
let () =
|
||||||
|
try
|
||||||
|
List.iter (execute_ddl dbh) ddl_statements;
|
||||||
|
Printf.printf "Database initialized successfully.\n"
|
||||||
|
with
|
||||||
|
| PGOCaml.Error err ->
|
||||||
|
Printf.eprintf "Error initializing database: %s\n" (PGOCaml.string_of_error err)
|
||||||
|
| exn ->
|
||||||
|
Printf.eprintf "Unexpected error: %s\n" (Printexc.to_string exn)
|
||||||
|
in
|
||||||
|
|
||||||
|
(* Close the connection *)
|
||||||
|
PGOCaml.close dbh
|
||||||
|
|
31
metadata_store.opam
Normal file
31
metadata_store.opam
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# This file is generated by dune, edit dune-project instead
|
||||||
|
opam-version: "2.0"
|
||||||
|
synopsis: "A short synopsis"
|
||||||
|
description: "A longer description"
|
||||||
|
maintainer: ["Maintainer Name"]
|
||||||
|
authors: ["Author Name"]
|
||||||
|
license: "LICENSE"
|
||||||
|
tags: ["topics" "to describe" "your" "project"]
|
||||||
|
homepage: "https://github.com/username/reponame"
|
||||||
|
doc: "https://url/to/documentation"
|
||||||
|
bug-reports: "https://github.com/username/reponame/issues"
|
||||||
|
depends: [
|
||||||
|
"ocaml"
|
||||||
|
"dune" {>= "3.16"}
|
||||||
|
"odoc" {with-doc}
|
||||||
|
]
|
||||||
|
build: [
|
||||||
|
["dune" "subst"] {dev}
|
||||||
|
[
|
||||||
|
"dune"
|
||||||
|
"build"
|
||||||
|
"-p"
|
||||||
|
name
|
||||||
|
"-j"
|
||||||
|
jobs
|
||||||
|
"@install"
|
||||||
|
"@runtest" {with-test}
|
||||||
|
"@doc" {with-doc}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
dev-repo: "git+https://github.com/username/reponame.git"
|
0
test/test_metadata_store.ml
Normal file
0
test/test_metadata_store.ml
Normal file
Loading…
Reference in New Issue
Block a user