Rebuild the report database. This is necessary when the orderly database schema changes, and you will be prompted to run this function after upgrading orderly in that case.
Arguments
- root
The path to an orderly root directory, or
NULL
(the default) to search for one from the current working directory iflocate
isTRUE
.- locate
Logical, indicating if the configuration should be searched for. If
TRUE
andconfig
is not given, then orderly looks in the working directory and up through its parents until it finds anorderly_config.yml
file.- verbose
Logical, indicating if information about the rebuild should be printed as it runs
- if_schema_changed
Logical, indicating if the rebuild should take place only if the schema has changed. This is designed to be safe to use in (say) deployment scripts because it will be fast enough to call regularly.
Details
The report database (orderly's "destination" database) is
essentially an index over all the metadata associated with
reports. It is used by orderly itself, and can be used by
applications that extend orderly (e.g.,
OrderlyWeb. All the
data in this database can be rebuilt from files stored with the
committed (archive) orderly reports, using the
orderly_rebuild
function.
Examples
path <- orderly::orderly_example("minimal")
id <- orderly::orderly_run("example", root = path)
#> [ name ] example
#> [ id ] 20230621-105035-2d23038e
#> [ start ] 2023-06-21 10:50:35
#> [ data ] source => dat: 20 x 2
#>
#> > png("mygraph.png")
#>
#> > par(mar = c(15, 4, 0.5, 0.5))
#>
#> > barplot(setNames(dat$number, dat$name), las = 2)
#>
#> > dev.off()
#> agg_png
#> 2
#> [ end ] 2023-06-21 10:50:35
#> [ elapsed ] Ran report in 0.01635027 secs
#> [ artefact ] mygraph.png: 175369b2bcf4115f343c8ad746c0c072
orderly::orderly_commit(id, root = path)
#> [ commit ] example/20230621-105035-2d23038e
#> [ copy ]
#> [ import ] example:20230621-105035-2d23038e
#> [ success ] :)
#> [1] "/tmp/RtmpGRuIRx/file47624d282b/archive/example/20230621-105035-2d23038e"
con <- orderly::orderly_db("destination", root = path)
DBI::dbReadTable(con, "report_version")
#> id report date displayname description
#> 1 20230621-105035-2d23038e example 2023-06-21 10:50:35 <NA> <NA>
#> connection published elapsed git_sha git_branch git_clean
#> 1 0 0 0.01635027 <NA> <NA> NA
DBI::dbDisconnect(con)
# The database can be removed and will be rebuilt if requested
# (this is only a good idea if you do not extend the database with
# your own fields - only the fields that orderly looks after can
# be recovered!)
file.remove(file.path(path, "orderly.sqlite"))
#> [1] TRUE
orderly::orderly_rebuild(path)
#> [ backup ] orderly.sqlite => backup/db/orderly.sqlite.20230621-105035
#> [ rebuild ] db
#> 20230621-105035-2d23038e (example)
file.exists(file.path(path, "orderly.sqlite"))
#> [1] TRUE
con <- orderly::orderly_db("destination", root = path)
DBI::dbReadTable(con, "report_version")
#> id report date displayname description
#> 1 20230621-105035-2d23038e example 2023-06-21 10:50:35 <NA> <NA>
#> connection published elapsed git_sha git_branch git_clean
#> 1 0 0 0.01635027 <NA> <NA> NA
DBI::dbDisconnect(con)
# It is safe to rebuild a database repeatedly, though this can be
# slow with larger databases.
orderly::orderly_rebuild(path)
#> [ backup ] orderly.sqlite => backup/db/orderly.sqlite.20230621-105035
#> [ rebuild ] db
#> 20230621-105035-2d23038e (example)