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

Port get_schema_via_mysqldump and other useful DB metadata functions to redcapcustodian #92

Open
ChemiKyle opened this issue Dec 21, 2022 · 0 comments

Comments

@ChemiKyle
Copy link
Contributor

Archiving and shutting down projects has created several (possibly generically) useful functions, we should consider porting these functions to redcapcustodian.

The code from STP is as follows:

get_schema_via_mysqldump <- function(table_name, host, database, username, password) {
  command <- paste(
    "mysqldump",
    "--no-data --skip-lock-tables --triggers --routines --events --skip-add-locks --skip-comments --no-tablespaces",
    paste0("--host=", host),
    paste0("--user=", username),
    "-p",
    database,
    table_name,
    "| sed -e 's/AUTO_INCREMENT=[[:digit:]]* //'",
    "| sed '/50013 DEFINER=/d'"
  )

  schema <- system(
    command = command,
    input = password,
    intern = TRUE
  )
  project_name <- tolower(word(table_name, 1, sep = "_"))
  schema_filename <- paste0(output_dir, "/", project_name, "_schema", ".sql")
  write(schema, schema_filename)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant