schema

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package schema provides database schema models for GNdb. Models are aligned with gnidump for gnverifier compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllModels

func AllModels() []interface{}

AllModels returns all schema models for GORM AutoMigrate.

func Migrate

func Migrate(db *gorm.DB) error

Migrate runs GORM AutoMigrate to create or update schema.

Types

type Canonical

type Canonical struct {
	// UUID v5 generated for simple canonical form.
	ID string `gorm:"type:uuid;primaryKey;autoIncrement:false"`

	// Canonical name-string
	Name string `gorm:"type:text;not null"`
}

Canonical is a 'simple' canonical form.

type CanonicalFull

type CanonicalFull struct {
	// UUID v5 generated for 'full' canonical form (with infraspecific ranks
	// and hybrid signs for named hybrids).
	ID string `gorm:"type:uuid;primaryKey;autoIncrement:false"`

	// Canonical name-string
	Name string `gorm:"type:text;not null"`
}

CanonicalFull ia a full canonical form.

type CanonicalStem

type CanonicalStem struct {
	// UUID v5 for the stemmed derivative of a simple canonical form.
	ID string `gorm:"type:uuid;primaryKey;autoIncrement:false"`

	// Stemmed canonical name-string
	Name string `gorm:"type:text;not null"`
}

CanonicalStem is a stemmed derivative of a simple canonical form.

type DataSource

type DataSource struct {
	// ID is a hard-coded identifier that aligns with historical IDs from
	// older versions of the resolver.
	ID int `gorm:"type:smallint;primaryKey;autoIncrement:false"`

	// UUID is a unique identifier assigned to the resource upon creation.
	// While not shown to users, it's handy for importing data from DwCA files.
	UUID string `gorm:"type:uuid;default:'00000000-0000-0000-0000-000000000000'"`

	// Title is the full, descriptive title of the dataset, usually as provided
	// by its creators.
	Title string `gorm:"type:varchar(255)"`

	// TitleShort is a concise or abbreviated version of the dataset title.
	TitleShort string `gorm:"type:varchar(50)"`

	// Version denotes the specific version of the dataset, if applicable.
	Version string `gorm:"type:varchar(50)"`

	// RevisionDate indicates when the dataset was created or last revised.
	// It follows the format 'YYYY-MM-DD', 'YYYY-MM', or 'YYYY'.
	RevisionDate string

	// DOI is the Digital Object Identifier for the dataset, if available.
	DOI string `gorm:"type:varchar(50)"`

	// Citation provides the recommended way to reference or cite the dataset.
	Citation string

	// Authors lists the individuals or organizations responsible for creating
	// the dataset.
	Authors string

	// Description offers a summary of the dataset's content and purpose.
	// It may also include additional, unstructured metadata.
	Description string

	// WebsiteURL is the primary web address associated with the dataset.
	WebsiteURL string `gorm:"type:varchar(255)"`

	// DataURL is the original URL from which the dataset was downloaded.
	DataURL string `gorm:"type:varchar(255)"`

	// OutlinkURL is a template for generating external links to specific records
	// within the dataset. It includes a placeholder '{}' for the record's
	// OutlinkID.
	OutlinkURL string

	// IsOutlinkReady signifies whether the data source has sufficient metadata,
	// URLs, and harvests to be considered a 'mature' and reliable source on
	// gnames. Resources with outdated harvests or missing WebsiteURL/OutlinkURLs
	// will typically have this flag set to false.
	IsOutlinkReady bool

	// IsCurated is true when we are aware if the dataset has undergone
	// significant manual curation.
	IsCurated bool

	// IsAutoCurated is true when we are aware if the dataset has undergone
	// significant automated curation using scripts.
	IsAutoCurated bool

	// HasTaxonData indicates whether the dataset contains taxonomic data.
	HasTaxonData bool

	// RecordCount represents the total number of name records in the dataset.
	RecordCount int `gorm:"type:integer"`

	// VernRecordCount is the number of vernacular string indices.
	VernRecordCount int `gorm:"type:integer"`

	// UpdatedAt records the timestamp of the dataset's last import.
	// This might not necessarily coincide with the dataset's creation date.
	UpdatedAt time.Time `gorm:"type:timestamp without time zone"`
}

DataSource stores metadata associated with a dataset.

type NameString

type NameString struct {
	// UUID v5 generated from the name-string using DNS:"globalnames.org" as
	// a seed.
	ID string `gorm:"type:uuid;primaryKey;autoIncrement:false"`

	// Name-string with authorships and annotations as it is given by a dataset.
	// Sometimes an authorship is concatenated with a name-string by our
	// import scripts.
	Name string `gorm:"type:text;not null"`

	// Year is the year when a name was published
	Year sql.NullInt16 `gorm:"type:int"`

	// Number of elements in a 'classic' Linnaen name: 0 - unknown, not available,
	// 1 - uninomial, 2 - binomial, 3 - trinomial etc.
	// Cardinality can be used to filter out surrogates and hybrid formulas --
	// they would have cardinality 0.
	Cardinality sql.NullInt32 `gorm:"type:int"`

	// UUID v5 generated for simple canonical form.
	CanonicalID sql.NullString `gorm:"type:uuid;index:canonical"`

	// UUID v5 generated for 'full' canonical form (with infraspecific ranks
	// and hybrid signs for named hybrids).
	CanonicalFullID sql.NullString `gorm:"type:uuid;index:canonical_full"`

	// UUID v5 for the stemmed derivative of a simple canonical form.
	CanonicalStemID sql.NullString `gorm:"type:uuid;index:canonical_stem"`

	// Virus indicates if a name-string seems to be virus-like.
	Virus bool `gorm:"type:bool"`

	// Bacteria is true if parser marks a name as from Bactrial Code.
	Bacteria bool `gorm:"type:bool;not null;default:false"`

	// Surrogate indicates if a name-string is a surrogate name.
	Surrogate bool `gorm:"type:bool"`

	// ParseQuality is numeric representation of the quality of parsing.
	// 0 - no parse, 1 - clear parse, 2 - some problems, 3 - big problems.
	ParseQuality int `gorm:"type:integer;not null;default:0"`
}

NameString is a name-string extracted from a dataset.

type NameStringIndex

type NameStringIndex struct {
	// DataSourceID refers to a data-source ID.
	DataSourceID int `gorm:"primaryKey;autoIncrement:false"`

	// RecordID is a unique ID for record. We do our best to
	// get it from the record IDs, either global or local,
	// but if all fails, id is assigned by gnames in a format
	// of 'gn_{int}'.
	RecordID string `gorm:"type:varchar(255);primaryKey"`

	// NameStringID is UUID5 of a full name-string from the dataset.
	NameStringID string `gorm:"type:uuid;index:name_string_id"`

	// The id to create an outlink.
	OutlinkID string `gorm:"type:varchar(255)"`

	// Global id from the dataset.
	GlobalID string `gorm:"type:varchar(255)"`

	// NameID is an ID of a nomenclatural name provided by data source.
	NameID string `gorm:"type:varchar(255)"`

	// Local id from the dataset.
	LocalID string `gorm:"type:varchar(255)"`

	// Nomenclatural code ID. 0 - no info, 1 - ICZN, 2 - ICN, 3 - ICNP, 4 - ICTV.
	CodeID int `gorm:"type:smallint"`

	// The rank of the name.
	Rank string `gorm:"type:varchar(255)"`

	// TaxonomicStatus provides information if name is accepted, bare name,
	// synonym etc.
	TaxonomicStatus string `gorm:"type:varchar(255)"`

	// RecordID of a currently accepted name-string for the taxon.
	AcceptedRecordID string `gorm:"type:varchar(255);primaryKey;index:accepted_record_id"`

	// Pipe-delimited string containing classification supplied with the resource.
	Classification string

	// RecordIDs of the classificatiaon elements (if given).
	ClassificationIDs string

	// Ranks of the classification elements.
	ClassificationRanks string
}

NameStringIndex is a name-strings relations to datasets.

type VernacularString

type VernacularString struct {
	// UUID v5 generated from the name-string using DNS:"globalnames.org" as
	// a seed.
	ID string `gorm:"type:uuid;primaryKey;autoIncrement:false"`

	// Name is a vernacular name as it is given by a dataset.
	Name string `gorm:"type:text;index:vern_str_name_idx;not null"`
}

VernacularString contains vernacular name-strings.

type VernacularStringIndex

type VernacularStringIndex struct {
	// DataSourceID refers to a data-source ID.
	DataSourceID int `gorm:"index:vernacular_string_idx_idx"`

	// RecordID is a unique ID for record. We do our best to
	// get it from the record IDs, either global or local,
	// but if all fails, id is assigned by gnames in a format
	// of 'gn_{int}'.
	RecordID string `gorm:"type:varchar(255);index:vernacular_string_idx_idx"`

	// VernacularStringID is UUID5 of a full name-string from the dataset.
	VernacularStringID string `gorm:"type:uuid;index:vernacular_string_id"`

	// LanguageOrig of the vernacular name verbatim.
	LanguageOrig string `gorm:"type:varchar(255)"`

	// Language of the vernacular name after normalization.
	Language string `gorm:"type:varchar(255)"`

	// LangCode is a three-letter code of the language. The code
	// is received programmatically and might contain errors.
	LangCode string `gorm:"type:varchar(3);index:vernacular_string_idx_idx"`

	// Locality of the vernacular name.
	Locality string `gorm:"type:varchar(255)"`

	// CountryCode of the vernacular name.
	CountryCode string `gorm:"type:varchar(50)"`

	// Preferred is set to true if this name for the particular language
	// is preferred.
	Preferred bool
}

VernacularStringIndex links vernacular strings to datasets.

type Word

type Word struct {
	// ID generated by combinding modified word and type converted to integer
	//together with a pipe, and generating UUID5 from it.
	//For example: "alb|2"
	ID string `gorm:"primaryKey;type:uuid;autoIncrement:false"`

	// Normalized is the word normalized by GNparser. This field is used
	// for sorting results.
	Normalized string `gorm:"type:text;primaryKey;autoIncrement:false"`

	// Modified is a heavy-normalized word. This field is used for matching.
	Modified string `gorm:"type:text;not null;index:words_modified"`

	// TypeID is the integer representation of parsed.WordType
	// from GNparser.
	TypeID int
}

Word is a word from a name-string.

type WordNameString

type WordNameString struct {
	// WordID is the identifier of a word.
	WordID string `gorm:"primaryKey;type:uuid;autoIncrement:false"`

	// NameStringID is UUID5 of a full name-string from the dataset.
	NameStringID string `gorm:"primaryKey;type:uuid;autoIncrement:false"`

	// CanonicalID is UUID5 of a simple canonical form of a name
	CanonicalID string `gorm:"type:uuid;not_null"`
}

WordNameString is the meaning of a word in a name-string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL