Skip to content

Commit 1cd0839

Browse files
committed
Adding art_language db table
1 parent 910c388 commit 1cd0839

File tree

8 files changed

+149
-7
lines changed

8 files changed

+149
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ $RECYCLE.BIN/
137137

138138
### Data ###
139139
*.json
140-
*.sql
140+
data/*.sql
141141
*.xml
142142
*.csv
143143
!html_tags.txt

alembic/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# since 'utils/' and 'alembic/' are siblings folders, we can import the
2020
# relative module using the append method of the sys.path module
2121
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
22-
from fbo_scraper.db.db_utils import get_db_url
22+
from fbo_scraper.db.connection import get_db_url
2323

2424
config.set_main_option("sqlalchemy.url", get_db_url())
2525
from fbo_scraper.db import db
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Adding art language table
2+
3+
Revision ID: 2e38f559933b
4+
Revises: 78823e9293e9
5+
Create Date: 2024-06-25 14:55:27.913403
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from sqlalchemy.dialects import postgresql
11+
from sqlalchemy.dialects.postgresql import JSONB
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '2e38f559933b'
15+
down_revision = None
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.create_table('art_language',
23+
sa.Column('id', sa.Integer(), nullable=False),
24+
sa.Column('solicitation_id', sa.Integer(), nullable=True),
25+
sa.Column('language', JSONB(), nullable=False),
26+
sa.Column('createdAt', sa.DateTime(), nullable=False),
27+
sa.Column('updatedAt', sa.DateTime(), nullable=True),
28+
sa.ForeignKeyConstraint(['solicitation_id'], ['solicitations.id'], name=op.f('fk_art_language_solicitation_solicitations')),
29+
sa.PrimaryKeyConstraint('id', name=op.f('pk_art_language'))
30+
)
31+
32+
# ### end Alembic commands ###
33+
34+
35+
def downgrade():
36+
# ### commands auto generated by Alembic - please adjust! ###
37+
38+
op.drop_table('art_language')
39+
# ### end Alembic commands ###

sql/migrations/add_art_language.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
BEGIN;
2+
3+
CREATE TABLE art_language (
4+
id SERIAL NOT NULL,
5+
solicitation_id INTEGER,
6+
language JSONB NOT NULL,
7+
"createdAt" TIMESTAMP WITHOUT TIME ZONE NOT NULL,
8+
"updatedAt" TIMESTAMP WITHOUT TIME ZONE,
9+
CONSTRAINT pk_art_language PRIMARY KEY (id),
10+
CONSTRAINT fk_art_language_solicitation_solicitations FOREIGN KEY(solicitation_id) REFERENCES solicitations (id)
11+
);
12+
13+
INSERT INTO alembic_version (version_num) VALUES ('2e38f559933b') RETURNING alembic_version.version_num;
14+
15+
COMMIT;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
BEGIN;
2+
3+
ALTER TABLE "Agencies" ALTER COLUMN "updatedAt" DROP NOT NULL;
4+
5+
ALTER TABLE "Predictions" ADD COLUMN "eitLikelihood" JSONB;
6+
7+
ALTER TABLE "Predictions" ADD COLUMN active BOOLEAN DEFAULT true;
8+
9+
ALTER TABLE "Predictions" ALTER COLUMN title SET NOT NULL;
10+
11+
ALTER TABLE "Predictions" ALTER COLUMN "solNum" SET NOT NULL;
12+
13+
ALTER TABLE "Predictions" ALTER COLUMN "noticeType" SET NOT NULL;
14+
15+
ALTER TABLE "Predictions" ALTER COLUMN "createdAt" SET NOT NULL;
16+
17+
ALTER TABLE "Predictions" ALTER COLUMN history SET DEFAULT '[]'::jsonb;
18+
19+
ALTER TABLE "Predictions" ADD CONSTRAINT "uq_Predictions_solNum" UNIQUE ("solNum");
20+
21+
ALTER TABLE "Predictions" DROP COLUMN feedback;
22+
23+
ALTER TABLE "Predictions" DROP COLUMN category_list;
24+
25+
ALTER TABLE "Surveys" ALTER COLUMN "updatedAt" DROP NOT NULL;
26+
27+
ALTER TABLE "Users" ALTER COLUMN "updatedAt" DROP NOT NULL;
28+
29+
ALTER TABLE agency_alias ALTER COLUMN agency_id SET NOT NULL;
30+
31+
ALTER TABLE agency_alias ALTER COLUMN "createdAt" SET NOT NULL;
32+
33+
ALTER TABLE agency_alias ALTER COLUMN "createdAt" SET DEFAULT now();
34+
35+
ALTER TABLE agency_alias ALTER COLUMN "updatedAt" DROP NOT NULL;
36+
37+
ALTER TABLE notice_type ADD COLUMN "createdAt" TIMESTAMP WITHOUT TIME ZONE NOT NULL;
38+
39+
ALTER TABLE notice_type ADD COLUMN "updatedAt" TIMESTAMP WITHOUT TIME ZONE;
40+
41+
ALTER TABLE survey_responses ALTER COLUMN "createdAt" SET NOT NULL;
42+
43+
CREATE INDEX "ix_survey_responses_solNum" ON survey_responses ("solNum");
44+
45+
ALTER TABLE survey_responses_archive ALTER COLUMN "createdAt" SET NOT NULL;
46+
47+
ALTER TABLE survey_responses_archive ALTER COLUMN "createdAt" SET DEFAULT now();
48+
49+
ALTER TABLE survey_responses_archive ALTER COLUMN "updatedAt" DROP NOT NULL;
50+
51+
ALTER TABLE survey_responses_archive ALTER COLUMN response SET DEFAULT '[]'::jsonb;
52+
53+
ALTER TABLE solicitations ADD CONSTRAINT "uq_solicitations_solNum" UNIQUE ("solNum");
54+
55+
ALTER TABLE solicitations ALTER COLUMN history SET DEFAULT '[]'::jsonb;
56+
57+
ALTER TABLE solicitations ALTER COLUMN action SET DEFAULT '[]'::jsonb;
58+
59+
ALTER TABLE solicitations ALTER COLUMN predictions SET DEFAULT '{"value": "red", "history": []}'::jsonb;
60+
61+
ALTER TABLE solicitations ALTER COLUMN compliant SET DEFAULT 0;
62+
63+
ALTER TABLE solicitations ALTER COLUMN active SET DEFAULT true;
64+
65+
ALTER TABLE solicitations ALTER COLUMN na_flag SET DEFAULT false;
66+
67+
ALTER TABLE solicitations ALTER COLUMN "updateAt" DROP NOT NULL;
68+
69+
ALTER TABLE attachment ALTER COLUMN "createdAt" SET NOT NULL;
70+
71+
ALTER TABLE attachment ALTER COLUMN "createdAt" SET DEFAULT now();
72+
73+
ALTER TABLE notice ALTER COLUMN "createdAt" SET NOT NULL;
74+
75+
ALTER TABLE notice ALTER COLUMN "createdAt" SET DEFAULT now();
76+
77+
78+
COMMIT;
79+

src/fbo_scraper/db/db.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class Solicitation(Base):
215215
"Attachment", back_populates="solicitation", cascade="all, delete-orphan"
216216
)
217217

218+
class ARTLanguage(Base):
219+
__tablename__ = "art_language"
220+
id = Column(Integer, primary_key=True)
221+
solicitation_id = Column(Integer, ForeignKey("solicitations.id"))
222+
language = Column(JSONB, nullable=False)
223+
createdAt = Column(DateTime, nullable=False, default=func.now())
224+
updatedAt = Column(DateTime, onupdate=func.now())
225+
226+
solicitation = relationship("Solicitation", back_populates="art_language")
218227

219228
class SurveyResponse(Base):
220229
__tablename__ = "survey_responses"

src/fbo_scraper/util/ebuy_csv.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,21 @@ def ebuy_process(options):
403403
predict = Predict(best_model_path=options.model_path)
404404

405405
rfq_data = parse_csv(options.file_path)
406-
logger.debug("After Parse: ", rfq_data[0])
406+
#logger.debug("After Parse: ", rfq_data[0])
407407

408408
rfq_data = filter_out_no_attachments(rfq_data)
409-
logger.debug("After Filter: ", rfq_data[0])
409+
#logger.debug("After Filter: ", rfq_data[0])
410410

411411
rfq_data = filter_out_no_naics(rfq_data)
412-
logger.debug("After NAICS Filter: ", rfq_data[0])
412+
#logger.debug("After NAICS Filter: ", rfq_data[0])
413413

414414
rfq_data = rfq_relabeling(rfq_data)
415-
logger.debug("After Labeling: ", rfq_data[0])
415+
#logger.debug("After Labeling: ", rfq_data[0])
416416

417417
rfq_data = grab_attachment_texts(rfq_data)
418418

419419
predicted_data = predict.insert_predictions(rfq_data)
420-
logger.debug(predicted_data[0])
420+
#logger.debug(predicted_data[0])
421421

422422
with dal.Session.begin() as session:
423423
if predicted_data:

0 commit comments

Comments
 (0)