Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line enhancements #112

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
0734540
add add subcommand
lmcmicu Sep 18, 2024
9eef094
read input from stdin in Add
lmcmicu Sep 18, 2024
c32574f
use nested subcommands
lmcmicu Sep 19, 2024
e2038fb
add get subcommand, alphabetize match arms in main(), add get_row() stub
lmcmicu Sep 19, 2024
d160339
move all positional arguments to leaf subcommands
lmcmicu Sep 19, 2024
a73e21a
reorganize toolkit
lmcmicu Sep 19, 2024
4b89c58
implement API version of get_row()
lmcmicu Sep 19, 2024
9126d61
rename get_row() to get_row_from_db() and get_row_from_db() to get_ro…
lmcmicu Sep 19, 2024
d0002e8
use AnyKind instead of AnyPool where possible
lmcmicu Sep 19, 2024
fadfa65
add DbKind
lmcmicu Sep 20, 2024
ce528e2
small reorg and name change for functions that use transactions
lmcmicu Sep 20, 2024
5fab3e4
add 'get cell' and 'get value' subcommands
lmcmicu Sep 20, 2024
65de31c
correct SerdeValues in get_row_from_db()
lmcmicu Sep 20, 2024
89ad162
implement get table
lmcmicu Oct 3, 2024
ce48032
get source and database from environment if not specified
lmcmicu Oct 3, 2024
7ac4568
implement get messages
lmcmicu Oct 3, 2024
93884df
implement CLI validate
lmcmicu Oct 4, 2024
9b2e520
export environment vars
lmcmicu Oct 4, 2024
266301e
fix tests
lmcmicu Oct 4, 2024
536585b
use simple json for input rows
lmcmicu Oct 4, 2024
c2ababb
implement CLI update and delete
lmcmicu Oct 4, 2024
2bf060c
add subcommands for update and delete
lmcmicu Oct 6, 2024
885d2cb
make row and column optional when getting messages
lmcmicu Oct 6, 2024
10fbf70
add add message
lmcmicu Oct 6, 2024
b293aa4
add update message
lmcmicu Oct 6, 2024
228acc3
add delete message
lmcmicu Oct 6, 2024
49b70cc
allow to delete multiple messages
lmcmicu Oct 7, 2024
28b21db
add undo redo to cli
lmcmicu Oct 7, 2024
bf670d3
exit with correct status for cli-validate
lmcmicu Oct 7, 2024
78ade3e
add cli history
lmcmicu Oct 12, 2024
4ec4240
history output tweaks
lmcmicu Oct 13, 2024
92bc665
include redo stack in history
lmcmicu Oct 13, 2024
d2a8fd7
do not redo orphaned history entries; add --rule option for get and d…
lmcmicu Oct 15, 2024
69f721c
reorganization and refactoring
lmcmicu Oct 18, 2024
7ad2a15
indicate move operations properly in history
lmcmicu Oct 19, 2024
6091766
add move CLI operation
lmcmicu Oct 19, 2024
208b983
add get-config subcommands
lmcmicu Oct 20, 2024
30489d9
use new get-config CLI syntax in test script
lmcmicu Oct 20, 2024
bf93e46
add CLI config add table
lmcmicu Oct 21, 2024
4346bab
implement CLI save-as
lmcmicu Oct 21, 2024
2d32493
eliminate config and get-config categories and redistribute their sub…
lmcmicu Oct 22, 2024
3df069b
first pass implemention of add_column()
lmcmicu Oct 25, 2024
09ca56f
return error when input columns don't exist
lmcmicu Oct 25, 2024
a263cf4
(WIP) add column
lmcmicu Oct 25, 2024
bc8dd3b
add datatype
lmcmicu Oct 29, 2024
751b3fd
make inner functions outer
lmcmicu Oct 30, 2024
6282101
implement delete column and datatype
lmcmicu Oct 30, 2024
672cab4
implement delete table
lmcmicu Oct 30, 2024
67ab925
implement move column
lmcmicu Oct 30, 2024
92ed973
implement (WIP) rename column, datatype
lmcmicu Oct 31, 2024
45c3731
reimplement drop, implement truncate
lmcmicu Nov 1, 2024
ece12c7
load after modifying columns and tables
lmcmicu Nov 1, 2024
54b4adc
add -all variants
lmcmicu Nov 4, 2024
ddf343d
add datatype name to list type, fix condition case statement in renam…
lmcmicu Nov 5, 2024
c8f70d8
refactor CLI operations into separate module
lmcmicu Nov 5, 2024
9db2e4d
remove old comment
lmcmicu Nov 5, 2024
d8853fb
reorder functions in cli.rs
lmcmicu Nov 5, 2024
30b8bd9
factor out cli.rs into public functions
lmcmicu Nov 5, 2024
9e98d44
change to build_valve() signature, plus miscellaneous improvements an…
lmcmicu Nov 6, 2024
40aab6e
tweak
lmcmicu Nov 6, 2024
9c42afe
accept both "row" and "row_number" in input JSON
lmcmicu Nov 7, 2024
815be75
update rule conditions when renaming datatypes
lmcmicu Nov 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ build = "build.rs"
lalrpop = { version = "0.19.9", features = ["lexer"] }

[dependencies]
ansi_term = "0.12"
anyhow = "1.0"
async-std = { version = "1", features = [ "attributes" ] }
async-recursion = "1.0"
clap = { version = "4.5", features = ["derive", "wrap_help"] }
clap = { version = "4.5", features = ["derive", "env", "wrap_help"] }
crossbeam = "0.8"
csv = "1.1"
enquote = "1.1"
Expand Down
30 changes: 15 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pg_connect_string := postgresql:///valve_postgres
.PHONY: sqlite_test
sqlite_test: build/valve.db test/src/table.tsv | test/output
@echo "Testing valve on sqlite ..."
./valve --assume-yes load test/src/table.tsv build/valve.db
./valve --source test/src/table.tsv --database build/valve.db --assume-yes load-all
test/round_trip.sh $^
scripts/export_messages.py $< $| $(tables_to_test)
diff --strip-trailing-cr -q test/expected/messages.tsv test/output/messages.tsv
Expand All @@ -78,7 +78,7 @@ pg_test: valve test/src/table.tsv | test/output
cp -f test/src/ontology/readonly3_postgresql_load.sql test/output/readonly3.sql
chmod u+x test/output/readonly1.sh
psql $(pg_connect_string) < test/src/ontology/view3_postgresql.sql
./$< --assume-yes load $(word 2,$^) $(pg_connect_string)
./$< --source $(word 2,$^) --database $(pg_connect_string) --assume-yes load-all
test/round_trip.sh $(pg_connect_string) $(word 2,$^)
scripts/export_messages.py $(pg_connect_string) $| $(tables_to_test)
diff --strip-trailing-cr -q test/expected/messages.tsv test/output/messages.tsv
Expand All @@ -95,30 +95,30 @@ api_test: sqlite_api_test pg_api_test
.PHONY: sqlite_api_test
sqlite_api_test: valve test/src/table.tsv build/valve.db test/insert_update.sh | test/output
@echo "Testing API functions on sqlite ..."
./$< --assume-yes test-api $(word 2,$^) $(word 3,$^)
./$< --source $(word 2,$^) --database $(word 3,$^) --assume-yes test-api
$(word 4,$^) $(word 3,$^) $(word 2,$^)
scripts/export_messages.py $(word 3,$^) $| $(tables_to_test)
diff --strip-trailing-cr -q test/expected/messages_after_api_test.tsv test/output/messages.tsv
echo "select \"history_id\", \"table\", \"row\", \"from\", \"to\", \"summary\", \"user\", \"undone_by\" from history where history_id < 16 order by history_id" | sqlite3 -header -tabs build/valve.db > test/output/history.tsv
diff --strip-trailing-cr -q test/expected/history.tsv test/output/history.tsv
# We drop all of the db tables because the schema for the next test (random test) is different
# from the schema used for this test.
./$< --assume-yes drop-all $(word 2,$^) $(word 3,$^)
./$< --source $(word 2,$^) --database $(word 3,$^) --assume-yes drop-all
@echo "Test succeeded!"

.PHONY: pg_api_test
pg_api_test: valve test/src/table.tsv test/insert_update.sh | test/output
@echo "Testing API functions on postgresql ..."
./$< --assume-yes load $(word 2,$^) $(pg_connect_string)
./$< --assume-yes test-api $(word 2,$^) $(pg_connect_string)
./$< --source $(word 2,$^) --database $(pg_connect_string) --assume-yes load-all
./$< --source $(word 2,$^) --database $(pg_connect_string) --assume-yes test-api
$(word 3,$^) $(pg_connect_string) $(word 2,$^)
scripts/export_messages.py $(pg_connect_string) $| $(tables_to_test)
diff --strip-trailing-cr -q test/expected/messages_after_api_test.tsv test/output/messages.tsv
psql $(pg_connect_string) -c "COPY (select \"history_id\", \"table\", \"row\", \"from\", \"to\", \"summary\", \"user\", \"undone_by\" from history where history_id < 16 order by history_id) TO STDOUT WITH NULL AS ''" > test/output/history.tsv
tail -n +2 test/expected/history.tsv | diff --strip-trailing-cr -q test/output/history.tsv -
# We drop all of the db tables because the schema for the next test (random test) is different
# from the schema used for this test.
./$< --assume-yes drop-all $(word 2,$^) $(pg_connect_string)
./$< --source $(word 2,$^) --database $(pg_connect_string) --assume-yes drop-all
@echo "Test succeeded!"

sqlite_random_db = build/valve_random.db
Expand All @@ -137,14 +137,14 @@ random_test_data: test/generate_random_test_data.py valve valve test/random_test
.PHONY: sqlite_random_test
sqlite_random_test: valve clean_random_data random_test_data | build test/output
@echo "Testing with random data on sqlite ..."
./$< --assume-yes load $(random_test_dir)/table.tsv $(sqlite_random_db)
./$< --source $(random_test_dir)/table.tsv --database $(sqlite_random_db) --assume-yes load-all
test/round_trip.sh $(sqlite_random_db) $(random_test_dir)/table.tsv
@echo "Test succeeded!"

.PHONY: pg_random_test
pg_random_test: valve clean_random_data random_test_data | build test/output
@echo "Testing with random data on postgresql ..."
./$< --assume-yes load $(random_test_dir)/table.tsv $(pg_connect_string)
./$< --source $(random_test_dir)/table.tsv --database $(pg_connect_string) --assume-yes load-all
test/round_trip.sh $(pg_connect_string) $(random_test_dir)/table.tsv
@echo "Test succeeded!"

Expand All @@ -158,9 +158,9 @@ test/penguins/src/data:
# it takes on my laptop (while plugged).
penguin_test_threshold = 50
num_penguin_rows = 100000
penguin_command_sqlite = ./valve --assume-yes load src/schema/table.tsv --initial-load penguins.db
penguin_command_pg = ./valve --assume-yes load src/schema/table.tsv $(pg_connect_string)
penguin_command_pg_drop = ./valve --assume-yes drop-all src/schema/table.tsv $(pg_connect_string)
penguin_command_sqlite = ./valve --source src/schema/table.tsv --database penguins.db --assume-yes load-all
penguin_command_pg = ./valve --source src/schema/table.tsv --database $(pg_connect_string) --assume-yes load-all
penguin_command_pg_drop = ./valve --source src/schema/table.tsv --database $(pg_connect_string) --assume-yes drop-all

.PHONY: penguin_test
penguin_test: valve | test/penguins/src/data
Expand Down Expand Up @@ -204,7 +204,7 @@ guess_test_data: test/generate_random_test_data.py $(guess_test_dir)/table1.tsv

$(guess_test_db): valve guess_test_data $(guess_test_dir)/*.tsv | build $(guess_test_dir)/ontology
rm -f $@
./$< --assume-yes load $(guess_test_dir)/table.tsv $@
./$< --source $(guess_test_dir)/table.tsv --database $@ --assume-yes load-all

# At last check, the performance test was running on GitHub's runner
# (Ubuntu 22.04.4 LTS, runner version 2.317.0) in just over 20s. GitHub
Expand All @@ -229,7 +229,7 @@ perf_test_data: test/generate_random_test_data.py valve confirm_overwrite.sh $(p

$(perf_test_db): valve perf_test_data $(perf_test_dir)/*.tsv | build $(perf_test_dir)/ontology
rm -f $@
timeout $(perf_test_threshold) time -p ./$< --assume-yes --verbose load $(perf_test_dir)/table.tsv --initial-load $@ || \
timeout $(perf_test_threshold) time -p ./$< --source $(perf_test_dir)/table.tsv --database $@ --assume-yes --verbose load-all || \
(echo "Performance test (SQLite) took longer than $(perf_test_threshold) seconds." && false)


Expand All @@ -239,7 +239,7 @@ sqlite_perf_test: $(perf_test_db) | test/output

.PHONY: pg_perf_test
pg_perf_test: valve $(perf_test_dir)/ontology | test/output
timeout $(perf_test_threshold) time -p ./$< --assume-yes --verbose load $(perf_test_dir)/table.tsv $(pg_connect_string) || \
timeout $(perf_test_threshold) time -p ./$< --source $(perf_test_dir)/table.tsv --database $(pg_connect_string) --assume-yes --verbose load-all || \
(echo "Performance test (PostgreSQL) took longer than $(perf_test_threshold) seconds." && false)
time -p scripts/export_messages.py $(pg_connect_string) $| $(tables_to_test)

Expand Down
4 changes: 3 additions & 1 deletion scripts/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def get_random_sample(table, sample_size):


def get_valve_config(valve_table):
result = subprocess.run(["./valve", "dump-config", valve_table], capture_output=True)
result = subprocess.run(
["./valve", "--source", valve_table, "--database", "", "dump-config"], capture_output=True
)
if result.returncode != 0:
error = result.stderr.decode()
output = result.stdout.decode()
Expand Down
Loading
Loading