Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
A simple database migration system for SQLite, based on sqlite-utils.
This project is an early alpha. Expect breaking changes.
This tool works as a plugin for sqlite-utils
. First install that:
pip install sqlite-utils
Then install this plugin like so:
sqlite-utils install sqlite-migrate
This tool works against migration files. A migration file looks like this:
from sqlite_migrate import Migrations
# Pick a unique name here - it must not clash with other migration sets that
# the user might run against the same database.
migration = Migrations("creatures")
# Use this decorator against functions that implement migrations
@migration()
def m001_create_table(db):
# db is a sqlite-utils Database instance
db["creatures"].create(
{"id": int, "name": str, "species": str},
pk="id"
)
@migration()
def m002_add_weight(db):
# db is a sqlite-utils Database instance
db["creatures"].add_column("weight", float)
Here is documentation on the Database instance passed to each migration function.
Running this command will execute those migrations in sequence against the specified database file.
Call migrate
with a path to your database and a path to the migrations file you want to apply:
sqlite-utils migrate creatures.db path/to/migrations.py
Running this multiple times will have no additional affect, unless you add more migration functions to the file.
If you call it without arguments it will search for and apply any migrations.py
files in the current directory or any of its subdirectories.
You can also pass the path to a directory, in which case all migrations.py
files in that directory and its subdirectories will be applied:
sqlite-utils migrate creatures.db path/to/parent/
When applying a single migrations file you can use the --stop-before
option to apply all migrations up to but excluding the specified migration:
sqlite-utils migrate creatures.db path/to/migrations.py --stop-before m002_add_weight
Add --list
to list migrations without running them, for example:
sqlite-utils migrate creatures.db --list
The output will look something like this:
Migrations for: creatures
Applied:
m001_create_table - 2023-07-23 04:09:40.324002
m002_add_weight - 2023-07-23 04:09:40.324649
m003_add_age - 2023-07-23 04:09:44.441616
m003_cleanup - 2023-07-23 04:09:44.443394
m004_cleanup - 2023-07-23 04:09:44.444184
m005_cleanup - 2023-07-23 04:09:44.445389
m006_cleanup - 2023-07-23 04:09:44.446742
m007_cleanup - 2023-07-23 04:16:02.529983
Pending:
m008_cleanup
Add -v
or --verbose
for verbose output, which will show the schema before and after the migrations were applied along with a diff:
sqlite-utils migrate creatures.db --verbose
Example output:
Migrating creatures.db
Schema before:
CREATE TABLE "_sqlite_migrations" (
[migration_set] TEXT,
[name] TEXT,
[applied_at] TEXT,
PRIMARY KEY ([migration_set], [name])
);
CREATE TABLE [creatures] (
[id] INTEGER PRIMARY KEY,
[name] TEXT,
[species] TEXT
, [weight] FLOAT);
Schema after:
CREATE TABLE "_sqlite_migrations" (
[migration_set] TEXT,
[name] TEXT,
[applied_at] TEXT,
PRIMARY KEY ([migration_set], [name])
);
CREATE TABLE "creatures" (
[id] INTEGER PRIMARY KEY,
[name] TEXT,
[species] TEXT,
[weight] FLOAT,
[age] INTEGER,
[shoe_size] INTEGER
);
Schema diff:
[applied_at] TEXT,
PRIMARY KEY ([migration_set], [name])
);
-CREATE TABLE [creatures] (
+CREATE TABLE "creatures" (
[id] INTEGER PRIMARY KEY,
[name] TEXT,
- [species] TEXT
-, [weight] FLOAT);
+ [species] TEXT,
+ [weight] FLOAT,
+ [age] INTEGER,
+ [shoe_size] INTEGER
+);
FAQs
A simple database migration system for SQLite, based on sqlite-utils
We found that sqlite-migrate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.