<commit_before># Copyright (C) <NAME> <<EMAIL>>
# See LICENSE for details.

from datetime import datetime

from sqlalchemy import (Boolean, Column, DateTime, ForeignKey, String, Text,
                        UniqueConstraint)
from sqlalchemy.dialects.mysql import INTEGER, SMALLINT
from sqlalchemy.orm import relationship

from platformio_api.database import Base


class PendingLibs(Base):
    __tablename__ = "pendinglibs"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    conf_url = Column(String(255), nullable=False, unique=True)
    added = Column(DateTime, nullable=False, default=datetime.utcnow())
    approved = Column(Boolean, nullable=False, default=False)
    processed = Column(Boolean, nullable=False, default=False)


class Authors(Base):
    __tablename__ = "authors"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    name = Column(String(30), nullable=False, unique=True)
    email = Column(String(50))
    url = Column(String(100))


class Keywords(Base):
    __tablename__ = "keywords"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    name = Column(String(20), unique=True, nullable=False)


class Attributes(Base):
    __tablename__ = "attributes"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    name = Column(String(20), unique=True, nullable=False)


class Libs(Base):
    __tablename__ = "libs"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    author_id = Column(INTEGER(unsigned=True), ForeignKey("authors.id"))
    latest_version_id = Column(INTEGER(unsigned=True))
    conf_url = Column(String(200), nullable=False)
    conf_sha1 = Column(String(40))
    example_nums = Column(SMALLINT(unsigned=True))
    updated = Column(DateTime, nullable=False, default=datetime.utcnow(),
                     index=True)
    synced = Column(DateTime, nullable=False, default=datetime.utcnow())

    author = relationship("Authors", uselist=False, lazy="joined",
                          backref="libs")
    fts = relationship("LibFTS", uselist=False, lazy="joined", cascade="all")
    versions = relationship("LibVersions", cascade="all")
    examples = relationship("LibExamples", cascade="all,delete-orphan")
    dllog = relationship("LibDLLog", cascade="all")
    dlstats = relationship("LibDLStats", uselist=False, cascade="all")
    attributes = relationship("Attributes", secondary="libs_attributes",
                              cascade="all")
    keywords = relationship("Keywords", secondary="libs_keywords",
                            cascade="all")


class LibFTS(Base):
    __tablename__ = "lib_fts"

    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    primary_key=True)
    name = Column(String(50), unique=True, nullable=False)
    description = Column(String(255))
    keywords = Column(String(255))
    examplefiles = Column(Text())


class LibVersions(Base):
    __tablename__ = "lib_versions"
    __table_args__ = (UniqueConstraint("lib_id", "name"),)

    id = Column(INTEGER(unsigned=True), primary_key=True)
    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    nullable=False)
    name = Column(String(20))
    released = Column(DateTime, nullable=False, default=datetime.utcnow())


class LibExamples(Base):
    __tablename__ = "lib_examples"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    nullable=False)
    name = Column(String(100))


class LibDLLog(Base):
    __tablename__ = "lib_dllog"

    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    primary_key=True)
    ip = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=False)
    date = Column(DateTime, nullable=False, default=datetime.utcnow())<commit_msg>Disable nullable for FTS fields<commit_after># Copyright (C) <NAME> <<EMAIL>>
# See LICENSE for details.

from datetime import datetime

from sqlalchemy import (Boolean, Column, DateTime, ForeignKey, String, Text,
                        UniqueConstraint)
from sqlalchemy.dialects.mysql import INTEGER, SMALLINT
from sqlalchemy.orm import relationship

from platformio_api.database import Base


class PendingLibs(Base):
    __tablename__ = "pendinglibs"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    conf_url = Column(String(255), nullable=False, unique=True)
    added = Column(DateTime, nullable=False, default=datetime.utcnow())
    approved = Column(Boolean, nullable=False, default=False)
    processed = Column(Boolean, nullable=False, default=False)


class Authors(Base):
    __tablename__ = "authors"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    name = Column(String(30), nullable=False, unique=True)
    email = Column(String(50))
    url = Column(String(100))


class Keywords(Base):
    __tablename__ = "keywords"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    name = Column(String(20), unique=True, nullable=False)


class Attributes(Base):
    __tablename__ = "attributes"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    name = Column(String(20), unique=True, nullable=False)


class Libs(Base):
    __tablename__ = "libs"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    author_id = Column(INTEGER(unsigned=True), ForeignKey("authors.id"))
    latest_version_id = Column(INTEGER(unsigned=True))
    conf_url = Column(String(200), nullable=False)
    conf_sha1 = Column(String(40))
    example_nums = Column(SMALLINT(unsigned=True))
    updated = Column(DateTime, nullable=False, default=datetime.utcnow(),
                     index=True)
    synced = Column(DateTime, nullable=False, default=datetime.utcnow())

    author = relationship("Authors", uselist=False, lazy="joined",
                          backref="libs")
    fts = relationship("LibFTS", uselist=False, lazy="joined", cascade="all")
    versions = relationship("LibVersions", cascade="all")
    examples = relationship("LibExamples", cascade="all,delete-orphan")
    dllog = relationship("LibDLLog", cascade="all")
    dlstats = relationship("LibDLStats", uselist=False, cascade="all")
    attributes = relationship("Attributes", secondary="libs_attributes",
                              cascade="all")
    keywords = relationship("Keywords", secondary="libs_keywords",
                            cascade="all")


class LibFTS(Base):
    __tablename__ = "lib_fts"

    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    primary_key=True)
    name = Column(String(50), unique=True, nullable=False)
    description = Column(String(255), nullable=False)
    keywords = Column(String(255), nullable=False)
    examplefiles = Column(Text(), nullable=False)


class LibVersions(Base):
    __tablename__ = "lib_versions"
    __table_args__ = (UniqueConstraint("lib_id", "name"),)

    id = Column(INTEGER(unsigned=True), primary_key=True)
    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    nullable=False)
    name = Column(String(20))
    released = Column(DateTime, nullable=False, default=datetime.utcnow())


class LibExamples(Base):
    __tablename__ = "lib_examples"

    id = Column(INTEGER(unsigned=True), primary_key=True)
    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    nullable=False)
    name = Column(String(100))


class LibDLLog(Base):
    __tablename__ = "lib_dllog"

    lib_id = Column(INTEGER(unsigned=True), ForeignKey("libs.id"),
                    primary_key=True)
    ip = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=False)
    date = Column(DateTime, nullable=False, default=datetime.utcnow())
{'fraction_non_alphanumeric': 0.12790697674418605, 'fraction_numerical': 0.008527131782945736, 'mean_word_length': 4.146941489361702, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4592172', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2293, 'n_words': 450}