Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicitly migrate on import #20

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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