-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3619 from freedomofpress/journalist-api-0.9.0
Add journalist interface API
- Loading branch information
Showing
21 changed files
with
1,977 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
securedrop/alembic/versions/3d91d6948753_create_source_uuid_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Create source UUID column | ||
Revision ID: 3d91d6948753 | ||
Revises: faac8092c123 | ||
Create Date: 2018-07-09 22:39:05.088008 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.sql import quoted_name | ||
import subprocess | ||
import uuid | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '3d91d6948753' | ||
down_revision = 'faac8092c123' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# Schema migration | ||
op.rename_table('sources', 'sources_tmp') | ||
|
||
# Add UUID column. | ||
op.add_column('sources_tmp', sa.Column('uuid', sa.String(length=36))) | ||
|
||
# Add UUIDs to sources_tmp table. | ||
conn = op.get_bind() | ||
sources = conn.execute(sa.text("SELECT * FROM sources_tmp")).fetchall() | ||
|
||
for source in sources: | ||
id = source.id | ||
source_uuid = str(uuid.uuid4()) | ||
conn.execute( | ||
sa.text("UPDATE sources_tmp SET uuid=('{}') WHERE id={}".format( | ||
source_uuid, id))) | ||
|
||
# Now create new table with unique constraint applied. | ||
op.create_table(quoted_name('sources', quote=False), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('uuid', sa.String(length=36), nullable=False), | ||
sa.Column('filesystem_id', sa.String(length=96), nullable=True), | ||
sa.Column('journalist_designation', sa.String(length=255), | ||
nullable=False), | ||
sa.Column('flagged', sa.Boolean(), nullable=True), | ||
sa.Column('last_updated', sa.DateTime(), nullable=True), | ||
sa.Column('pending', sa.Boolean(), nullable=True), | ||
sa.Column('interaction_count', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('uuid'), | ||
sa.UniqueConstraint('filesystem_id') | ||
) | ||
|
||
# Data Migration: move all sources into the new table. | ||
conn.execute(''' | ||
INSERT INTO sources | ||
SELECT id, uuid, filesystem_id, journalist_designation, flagged, | ||
last_updated, pending, interaction_count | ||
FROM sources_tmp | ||
''') | ||
|
||
# Now delete the old table. | ||
op.drop_table('sources_tmp') | ||
|
||
|
||
def downgrade(): | ||
with op.batch_alter_table('sources', schema=None) as batch_op: | ||
batch_op.drop_column('uuid') |
66 changes: 66 additions & 0 deletions
66
securedrop/alembic/versions/fccf57ceef02_create_submission_uuid_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""create submission uuid column | ||
Revision ID: fccf57ceef02 | ||
Revises: 3d91d6948753 | ||
Create Date: 2018-07-12 00:06:20.891213 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
import uuid | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'fccf57ceef02' | ||
down_revision = '3d91d6948753' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# Schema migration | ||
op.rename_table('submissions', 'submissions_tmp') | ||
|
||
# Add UUID column. | ||
op.add_column('submissions_tmp', sa.Column('uuid', sa.String(length=36))) | ||
|
||
# Add UUIDs to submissions_tmp table. | ||
conn = op.get_bind() | ||
submissions = conn.execute( | ||
sa.text("SELECT * FROM submissions_tmp")).fetchall() | ||
|
||
for submission in submissions: | ||
id = submission.id | ||
submission_uuid = str(uuid.uuid4()) | ||
conn.execute( | ||
sa.text("""UPDATE submissions_tmp | ||
SET uuid=('{}') | ||
WHERE id={}""".format(submission_uuid, id))) | ||
|
||
# Now create new table with unique constraint applied. | ||
op.create_table('submissions', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('uuid', sa.String(length=36), nullable=False), | ||
sa.Column('source_id', sa.Integer(), nullable=True), | ||
sa.Column('filename', sa.String(length=255), nullable=False), | ||
sa.Column('size', sa.Integer(), nullable=False), | ||
sa.Column('downloaded', sa.Boolean(), nullable=True), | ||
sa.ForeignKeyConstraint(['source_id'], ['sources.id'], ), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('uuid') | ||
) | ||
|
||
# Data Migration: move all submissions into the new table. | ||
conn.execute(''' | ||
INSERT INTO submissions | ||
SELECT id, uuid, source_id, filename, size, downloaded | ||
FROM submissions_tmp | ||
''') | ||
|
||
# Now delete the old table. | ||
op.drop_table('submissions_tmp') | ||
|
||
|
||
def downgrade(): | ||
with op.batch_alter_table('submissions', schema=None) as batch_op: | ||
batch_op.drop_column('uuid') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.