Sqlitestudio multiple primary keys3/17/2023 ![]() ![]() # identify the database file to contain the extracted schema: # create a lookup table (numeric table id -> python name) for later use: Print('Loaded', len(anvil_schema), 'table definitions.') Print('Loading Project File (to get the db schema).')Īnvil_schema = load_schema(schema_source_path) Schema_filename: pathlib.Path, # name of schema-only sqlite fileĭest_folder: pathlib.Path, # folder to contain full backup fileīase_dest_name: str, # base name of backup file in folder # Just in case we missed something, convert it to a data # The other fields in table are duplicates. # try to translate to something like the full-project formatįor column_name in [ 'server', 'client', 'app_id', If source_is_git: # instead of a full-project backup file With open(schema_source_path, encoding='utf-8') as schema_source: Schema_key = 'db_schema' if source_is_git else 'exported_table_schema' Source_is_git = (filename = 'anvil.yaml') Schema_source_path: pathlib.Path, # full path to app-as-yaml-file ![]() # a list of tables.) The resulting information is too sparse to be # column names via app_tables.my_table.list_columns(), but this gives yaml file is available, then one can get a list of a table's Prefer to read the smaller file when available (and current). # in the project, is much smaller, *and* more detailed (at the table # However, the newer anvil.yaml file, which is just one source file # "exported_table_schema:" before attempting to parse anything. We could speed this up by skipping to the line reading # several seconds, yet is likely to result in exactly the same schema as Import yaml # i.e., py -m pip install pyyaml # successfully identifies the application source file (.yaml) and logs in # This is the workhorse function, to run after the main program # Purpose: to back up an Anvil App's data (and schema) to a SQLite file. ![]() The Uplink Module (if there’s a better way to attach this, let me know) # Module: BackUpAnvilAppTables_work Schema_filename = Path('.'), # schema file will be written hereĭest_folder = Path('.'), # schema+data file will be written to this folderīase_dest_name = '.', # schema+data file name. Schema_source_path = Path('.'), # e.g., anvil.yaml # That usually means using the Server (not Client) credentials. # connect to your App with full table-access privileges. (And how do you keep logged-in users’ database activity from accidentally interfering with the ongoing Restore?)Īt least, with a backup, you can have something to restore, even if it’s not immediately clear how.įrom BackUpAnvilAppTables_work import do_backup Using Row IDs to tie it all together? Row IDs of deleted rows can’t be restored on insert, Anvil will generate brand-new ones. Restoring just the right data, safely, is likely to be very, very App-dependent. In that case, you might get mixed results. Users may very well be updating the database while a backup is running.Media objects are written to their own table.( py -m pip install pyyaml into your favorite Python virtual environment.) To read the YAML, it depends on pyyaml.So, at that point, this code will probably break. Anvil reserves the right to change the format of these files, and schemas, at any time. So you need to have a (reasonably) current backup of your App’s source code, for it to read. yaml files to get the database structure. If you do, please let me know how it went! If you have such columns, you’ll want to uncomment those lines (and test thoroughly!). (My tables don’t have any.) To avoid trouble, the (incomplete) code to handle that is commented out. I haven’t tried it with multi-link columns.It started out as a hard-coded script, but I’ve taken some steps to generalize it. I’ve written an Uplink module that backs up an App’s tables to a SQLite database file. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |