stashing code

This commit is contained in:
user
2025-10-20 17:07:41 +03:00
commit f5b99afc8f
890 changed files with 54823 additions and 0 deletions

175
packages/airportsdb/.gitignore vendored Normal file
View File

@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Caches
.cache
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Runtime data
pids
_.pid
_.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store

View File

@@ -0,0 +1,14 @@
import { defineConfig } from "drizzle-kit";
import "dotenv/config";
export default defineConfig({
schema: "./schema",
out: "./migrations",
dialect: "postgresql",
verbose: true,
strict: false,
dbCredentials: {
url: process.env.AIRPORTS_DB_URL ?? "",
},
});

View File

@@ -0,0 +1,17 @@
import "dotenv/config";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";
const dbUrl = process.env.AIRPORTS_DB_URL ?? "";
const client = postgres(dbUrl);
const db = drizzle(client, { schema });
export type AirportsDatabase = typeof db;
export * from "drizzle-orm";
export { db as airportsDb, schema };

View File

@@ -0,0 +1,30 @@
CREATE TABLE IF NOT EXISTS "airport" (
"id" serial PRIMARY KEY NOT NULL,
"type" varchar(64) NOT NULL,
"name" varchar(128) NOT NULL,
"gps_code" varchar(64) NOT NULL,
"ident" varchar(128),
"latitude_deg" numeric(10, 2),
"longitude_deg" numeric(10, 2),
"elevation_ft" numeric(10, 2),
"continent" varchar(64),
"country" varchar(172),
"iso_country" varchar(4) NOT NULL,
"iso_region" varchar(64) NOT NULL,
"municipality" varchar(64),
"scheduled_service" varchar(64),
"iata_code" varchar(16) NOT NULL,
"local_code" varchar(16) NOT NULL,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now(),
"search_vector" "tsvector" GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce("airport"."name", '')), 'A') ||
setweight(to_tsvector('english', coalesce("airport"."iata_code", '')), 'A') ||
setweight(to_tsvector('english', coalesce("airport"."municipality", '')), 'B') ||
setweight(to_tsvector('english', coalesce("airport"."country", '')), 'C')
) STORED
);
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "name_idx" ON "airport" USING btree ("name");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "gps_code_idx" ON "airport" USING btree ("gps_code");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "search_vector_idx" ON "airport" USING gin ("search_vector");

View File

@@ -0,0 +1,16 @@
-- Custom SQL migration file, put your code below! --
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS btree_gin;
CREATE INDEX IF NOT EXISTS "trgm_idx_airport_name"
ON airport USING gin ("name" gin_trgm_ops);
CREATE INDEX IF NOT EXISTS "trgm_idx_airport_iatacode"
ON airport USING gin ("iata_code" gin_trgm_ops);
CREATE INDEX IF NOT EXISTS "trgm_idx_airport_municipality"
ON airport USING gin ("municipality" gin_trgm_ops);
CREATE INDEX IF NOT EXISTS "trgm_idx_airport_country"
ON airport USING gin ("country" gin_trgm_ops);

View File

@@ -0,0 +1,198 @@
{
"id": "2202b3d8-281c-474f-903d-27296ca06458",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.airport": {
"name": "airport",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "varchar(128)",
"primaryKey": false,
"notNull": true
},
"gps_code": {
"name": "gps_code",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"ident": {
"name": "ident",
"type": "varchar(128)",
"primaryKey": false,
"notNull": false
},
"latitude_deg": {
"name": "latitude_deg",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": false
},
"longitude_deg": {
"name": "longitude_deg",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": false
},
"elevation_ft": {
"name": "elevation_ft",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": false
},
"continent": {
"name": "continent",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"country": {
"name": "country",
"type": "varchar(172)",
"primaryKey": false,
"notNull": false
},
"iso_country": {
"name": "iso_country",
"type": "varchar(4)",
"primaryKey": false,
"notNull": true
},
"iso_region": {
"name": "iso_region",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"municipality": {
"name": "municipality",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"scheduled_service": {
"name": "scheduled_service",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"iata_code": {
"name": "iata_code",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true
},
"local_code": {
"name": "local_code",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"search_vector": {
"name": "search_vector",
"type": "tsvector",
"primaryKey": false,
"notNull": false,
"generated": {
"as": "\n setweight(to_tsvector('english', coalesce(\"airport\".\"name\", '')), 'A') ||\n setweight(to_tsvector('english', coalesce(\"airport\".\"iata_code\", '')), 'A') ||\n setweight(to_tsvector('english', coalesce(\"airport\".\"municipality\", '')), 'B') ||\n setweight(to_tsvector('english', coalesce(\"airport\".\"country\", '')), 'C')\n ",
"type": "stored"
}
}
},
"indexes": {
"name_idx": {
"name": "name_idx",
"columns": [
{
"expression": "name",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"gps_code_idx": {
"name": "gps_code_idx",
"columns": [
{
"expression": "gps_code",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"search_vector_idx": {
"name": "search_vector_idx",
"columns": [
{
"expression": "search_vector",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "gin",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -0,0 +1,198 @@
{
"id": "864dcba9-6d53-4311-be3e-0a51a483dac2",
"prevId": "2202b3d8-281c-474f-903d-27296ca06458",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.airport": {
"name": "airport",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "varchar(128)",
"primaryKey": false,
"notNull": true
},
"gps_code": {
"name": "gps_code",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"ident": {
"name": "ident",
"type": "varchar(128)",
"primaryKey": false,
"notNull": false
},
"latitude_deg": {
"name": "latitude_deg",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": false
},
"longitude_deg": {
"name": "longitude_deg",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": false
},
"elevation_ft": {
"name": "elevation_ft",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": false
},
"continent": {
"name": "continent",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"country": {
"name": "country",
"type": "varchar(172)",
"primaryKey": false,
"notNull": false
},
"iso_country": {
"name": "iso_country",
"type": "varchar(4)",
"primaryKey": false,
"notNull": true
},
"iso_region": {
"name": "iso_region",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"municipality": {
"name": "municipality",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"scheduled_service": {
"name": "scheduled_service",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
},
"iata_code": {
"name": "iata_code",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true
},
"local_code": {
"name": "local_code",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"search_vector": {
"name": "search_vector",
"type": "tsvector",
"primaryKey": false,
"notNull": false,
"generated": {
"type": "stored",
"as": "\n setweight(to_tsvector('english', coalesce(\"airport\".\"name\", '')), 'A') ||\n setweight(to_tsvector('english', coalesce(\"airport\".\"iata_code\", '')), 'A') ||\n setweight(to_tsvector('english', coalesce(\"airport\".\"municipality\", '')), 'B') ||\n setweight(to_tsvector('english', coalesce(\"airport\".\"country\", '')), 'C')\n "
}
}
},
"indexes": {
"name_idx": {
"name": "name_idx",
"columns": [
{
"expression": "name",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"with": {},
"method": "btree",
"concurrently": false
},
"gps_code_idx": {
"name": "gps_code_idx",
"columns": [
{
"expression": "gps_code",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"with": {},
"method": "btree",
"concurrently": false
},
"search_vector_idx": {
"name": "search_vector_idx",
"columns": [
{
"expression": "search_vector",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"with": {},
"method": "gin",
"concurrently": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"views": {},
"sequences": {},
"roles": {},
"policies": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -0,0 +1,20 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1746008605929,
"tag": "0000_friendly_thunderbolts",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1746008876617,
"tag": "0001_military_hannibal_king",
"breakpoints": true
}
]
}

View File

@@ -0,0 +1,26 @@
{
"name": "@pkg/airports-db",
"module": "index.ts",
"type": "module",
"scripts": {
"db:gen": "drizzle-kit generate --config=drizzle.config.ts",
"db:drop": "drizzle-kit drop --config=drizzle.config.ts",
"db:push": "drizzle-kit push --config=drizzle.config.ts",
"db:migrate": "drizzle-kit generate --config=drizzle.config.ts && drizzle-kit push --config=drizzle.config.ts",
"db:forcemigrate": "drizzle-kit generate --config=drizzle.config.ts && drizzle-kit push --config=drizzle.config.ts --force",
"dev": "drizzle-kit studio --host=0.0.0.0 --port=5421 --config=drizzle.config.ts --verbose"
},
"devDependencies": {
"@types/bun": "latest",
"@types/pg": "^8.11.10",
"drizzle-kit": "^0.28.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"dotenv": "^16.4.7",
"drizzle-orm": "^0.36.1",
"postgres": "^3.4.5"
}
}

View File

@@ -0,0 +1,70 @@
import { SQL, sql } from "drizzle-orm";
import {
pgTable,
serial,
varchar,
decimal,
timestamp,
index,
customType,
} from "drizzle-orm/pg-core";
const tsvector = customType<{ data: unknown }>({
dataType() {
return "tsvector";
},
});
export const airport = pgTable(
"airport",
{
id: serial("id").primaryKey(),
type: varchar("type", { length: 64 }).notNull(),
name: varchar("name", { length: 128 }).notNull(),
gpsCode: varchar("gps_code", { length: 64 }).notNull(),
ident: varchar("ident", { length: 128 }),
latitudeDeg: decimal("latitude_deg", { precision: 10, scale: 2 }),
longitudeDeg: decimal("longitude_deg", {
precision: 10,
scale: 2,
}),
elevationFt: decimal("elevation_ft", { precision: 10, scale: 2 }),
continent: varchar("continent", { length: 64 }),
country: varchar("country", { length: 172 }),
isoCountry: varchar("iso_country", { length: 4 }).notNull(),
isoRegion: varchar("iso_region", { length: 64 }).notNull(),
municipality: varchar("municipality", { length: 64 }),
scheduledService: varchar("scheduled_service", { length: 64 }),
iataCode: varchar("iata_code", { length: 16 }).notNull(),
localCode: varchar("local_code", { length: 16 }).notNull(),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").defaultNow(),
searchVector: tsvector("search_vector").generatedAlwaysAs(
(): SQL => sql`
setweight(to_tsvector('english', coalesce(${airport.name}, '')), 'A') ||
setweight(to_tsvector('english', coalesce(${airport.iataCode}, '')), 'A') ||
setweight(to_tsvector('english', coalesce(${airport.municipality}, '')), 'B') ||
setweight(to_tsvector('english', coalesce(${airport.country}, '')), 'C')
`,
),
},
(table) => {
return {
nameIdx: index("name_idx").on(table.name),
gpsCodeIdx: index("gps_code_idx").on(table.gpsCode),
searchVectorIdx: index("search_vector_idx").using(
"gin",
table.searchVector,
),
};
},
);