Skip to content

Commit

Permalink
Merge pull request #20 from edsu/implicit-migrate
Browse files Browse the repository at this point in the history
Implicitly migrate on import
  • Loading branch information
Florents-Tselai committed Oct 21, 2023
2 parents 7ac8fdb + d41118d commit 79979eb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ pip install warcdb
```

```shell

# Create the database `archive.warcdb`.
warcdb init archive.warcdb

# Load the `archive.warcdb` file with data.
warcdb import archive.warcdb ./tests/google.warc ./tests/frontpages.warc.gz "https://tselai.com/data/google.warc"

Expand Down Expand Up @@ -44,10 +40,9 @@ Individual `.warc` files are read and parsed and their data is inserted into an
## Schema
If there is a new major or minor version of warcdb you may need to migrate existing databases to use the new database schema (if there have been any changes). To do this you first upgrade warcdb, and then migrate the database:
If there is a new major or minor version of warcdb you may need to migrate existing databases to use the new database schema (if there have been any changes). To do this you first upgrade warcdb, and then import into the database, which will make sure all migrations have been run. If you want to migrate the database explicitly you can:
```shell
pip install --upgrade warcdb
warcdb migrate archive.warcdb
```
Expand Down
6 changes: 0 additions & 6 deletions tests/test_warcdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@

def test_import(warc_path):
runner = CliRunner()

# initialize db
result = runner.invoke(warcdb_cli, ['init', db_file])
assert result.exit_code == 0

args = ["import", db_file, warc_path]
result = runner.invoke(warcdb_cli, args)
assert result.exit_code == 0
Expand All @@ -46,7 +41,6 @@ def test_import(warc_path):

def test_column_names():
runner = CliRunner()
runner.invoke(warcdb_cli, ['init', db_file])
runner.invoke(warcdb_cli, ["import", db_file, str(pathlib.Path('tests/google.warc'))])

# make sure that the columns are named correctly (lowercase with underscores)
Expand Down
18 changes: 4 additions & 14 deletions warcdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,10 @@ def __iadd__(self, r: ArcWarcRecord):
"Commands for interacting with .warcdb files\n\nBased on SQLite-Utils"


@warcdb_cli.command('init')
@click.argument(
"db_path",
type=click.Path(file_okay=True, dir_okay=False, exists=False, allow_dash=False),
)
def init (db_path):
"""
Initialize a new warcdb database
"""
db = WarcDB(db_path)
migration.apply(db.db)


@warcdb_cli.command('import')
@click.argument(
"db_path",
type=click.Path(file_okay=True, dir_okay=False, exists=True, allow_dash=False),
type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
)
@click.argument('warc_path',
type=click.STRING,
Expand All @@ -256,6 +243,9 @@ def import_(db_path, warc_path, batch_size):
"""
db = WarcDB(db_path, batch_size=batch_size)

# ensure the schema is there and up to date
migration.apply(db.db)

# if batch_size:
# warnings.warn("--batch-size has been temporarily disabled")

Expand Down

0 comments on commit 79979eb

Please sign in to comment.