Spaces:
Running
Running
| import datetime | |
| import uuid | |
| from sqlalchemy import Column, String, DateTime, Boolean, Text, JSON, Integer, Float, Index | |
| from core.subscription.db import Base | |
| class Grant(Base): | |
| __tablename__ = "grants" | |
| id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4())) | |
| source_id = Column(String, unique=True, index=True, nullable=False) | |
| name = Column(String, nullable=False) | |
| program = Column(String, nullable=True) | |
| status = Column(String, default="active", index=True) | |
| url = Column(String, nullable=True) | |
| deadline = Column(String, nullable=True) | |
| source = Column(String, nullable=False) | |
| instrument_type = Column(String, default="grant") | |
| is_financial_instrument = Column(Boolean, default=False) | |
| eligible_company_sizes = Column(JSON, nullable=True) | |
| eligible_regions = Column(JSON, nullable=True) | |
| eligible_beneficiaries = Column(JSON, nullable=True) | |
| eligible_pkd = Column(JSON, nullable=True) | |
| description = Column(Text, nullable=True) | |
| program_goals = Column(Text, nullable=True) | |
| eligibility_criteria = Column(Text, nullable=True) | |
| operator = Column(String, nullable=True, index=True) | |
| program_year = Column(Integer, nullable=True, index=True) | |
| budget_min_pln = Column(Float, nullable=True) | |
| budget_max_pln = Column(Float, nullable=True) | |
| regulation_url = Column(String, nullable=True) | |
| official_page_url = Column(String, nullable=True) | |
| application_url = Column(String, nullable=True) | |
| catalog_hidden = Column(Boolean, default=False, index=True) | |
| completeness_score = Column(Integer, default=0) | |
| source_credibility_score = Column(Float, default=0.5) | |
| eurlex_url = Column(String, nullable=True) | |
| official_doc_url = Column(String, nullable=True) | |
| precise_regulation_url = Column(String, nullable=True) | |
| is_outdated_warning = Column(Boolean, default=False) | |
| url_warning = Column(String, nullable=True) | |
| fetched_at = Column(DateTime, default=lambda: datetime.datetime.now(datetime.timezone.utc)) | |
| last_verified = Column(DateTime, nullable=True) | |
| search_document = Column(Text, nullable=True) | |
| raw_data = Column(JSON, nullable=True) | |
| class GrantVersion(Base): | |
| """Wersjonowanie kluczowych zmian (regulamin, termin, status).""" | |
| __tablename__ = "grant_versions" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| grant_source_id = Column(String, index=True, nullable=False) | |
| field_name = Column(String, nullable=False, index=True) | |
| old_value = Column(Text, nullable=True) | |
| new_value = Column(Text, nullable=True) | |
| change_summary = Column(Text, nullable=True) | |
| detected_at = Column( | |
| DateTime, | |
| default=lambda: datetime.datetime.now(datetime.timezone.utc), | |
| index=True, | |
| ) | |
| source = Column(String, default="import") | |
| requires_verification = Column(Boolean, default=False) | |
| class ResearchJob(Base): | |
| """Kolejka zadań badawczych (Live Research Layer).""" | |
| __tablename__ = "research_jobs" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| job_type = Column(String, nullable=False, index=True) | |
| target_id = Column(String, nullable=True, index=True) | |
| target_url = Column(String, nullable=True) | |
| status = Column(String, default="pending", index=True) | |
| priority = Column(Integer, default=5) | |
| payload = Column(JSON, nullable=True) | |
| result = Column(JSON, nullable=True) | |
| error_message = Column(Text, nullable=True) | |
| created_at = Column( | |
| DateTime, | |
| default=lambda: datetime.datetime.now(datetime.timezone.utc), | |
| index=True, | |
| ) | |
| started_at = Column(DateTime, nullable=True) | |
| completed_at = Column(DateTime, nullable=True) | |
| class HumanVerificationItem(Base): | |
| """Human Verification Queue dla ważnych zmian.""" | |
| __tablename__ = "human_verification_queue" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| grant_source_id = Column(String, index=True, nullable=False) | |
| change_type = Column(String, nullable=False) | |
| field_name = Column(String, nullable=True) | |
| old_value = Column(Text, nullable=True) | |
| new_value = Column(Text, nullable=True) | |
| summary = Column(Text, nullable=True) | |
| status = Column(String, default="pending", index=True) | |
| priority = Column(Integer, default=5) | |
| created_at = Column( | |
| DateTime, | |
| default=lambda: datetime.datetime.now(datetime.timezone.utc), | |
| index=True, | |
| ) | |
| resolved_at = Column(DateTime, nullable=True) | |
| resolved_by = Column(String, nullable=True) | |
| resolution_note = Column(Text, nullable=True) | |
| Index("ix_grant_versions_grant_field", GrantVersion.grant_source_id, GrantVersion.field_name) | |
| Index("ix_research_jobs_status_priority", ResearchJob.status, ResearchJob.priority) | |