I'm trying to limit the size of a database in flask using Flask_SQLAlchemy. I want to start removing the oldest rows when the file size nears some limit set. I figured out how to remove rows from the beginning of the database, but the file size doesn't shrink because vacuuming isn't on (I think).
Is there a way to enable that or a better way to manage filesizes for a database in SQLAlchemy? I'm new to databases so any help is appreciated.
Thanks!
So I found a way to do this using SQLite3 in python, I'll add it here in case anyone finds this page and needs help. To vacuum after deleting, I just ran these three commands.
self.con = sqlite3.connect(databasename) # Open the database in sqlite
self.con.execute("VACUUM") # Execute the vacuum command
self.con.close() # Close the database
If anyone has a better way to do this which is native to SQLAlchemy please let us know!
I use my db = SQLAlchemy() object
and call
with db.engine.begin() as conn:
conn.execute("VACUUM")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With