sqlite_clone_migrate_table
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
There are a lot of migrations that SQLite doesn't allow, such as adding a primary key on a table. The way to accomplish this is by creating a new table with the schema you desire and then copying the rows of the old table into it.
This example shows how to:
- Get the schema for the existing table
- Create the new table
- Copy all rows from old to new
- Rename the old table to an archive (just in case)
- Rename the new table to the original table name
This script shows me adding a primary key constraint to the Profile
column of my DateMeDocs
database. I would console and comment out various parts of it as I went. You can see everything I did in the version history. The main tricky part for me was removing the duplicate primary key entries before doing the migration step, which is a useful thing anyways, from a data cleaning perspective.
Migrated from folder: Archive/sqlite_clone_migrate_table