GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — paste/install.py at master · lykoss/paste

Expand file tree

/

install.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
52 lines (42 loc) · 1.9 KB
/

install.py

Copy path

File metadata and controls

52 lines (42 loc) · 1.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from typing import Set
import pathlib
from db import DbConnection
def run():
"""
Execute the installer.
The installer will get the database schema up to current as well as set up any necessary
ancillary structures such as ElasticSearch indices and pipelines.
:return:
"""
with DbConnection() as conn:
conn.execute("""CREATE TABLE IF NOT EXISTS migrations (
migration_key varchar(150) PRIMARY KEY,
migration_time datetime) ENGINE=InnoDB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci""")
applied_migrations = set()
for row in conn.execute("SELECT migration_key FROM migrations"):
applied_migrations.add(row["migration_key"])
for p in sorted(pathlib.Path("migrations").iterdir()):
filename = str(p.name)
filepath = str(p.absolute())
if p.is_file() and filename[-4:] == ".sql":
_apply_migration(filename[:-4], filepath, conn, applied_migrations)
print("Install complete. Remember to configure your config.py and add a cron job or scheduled task for cron.py!")
def _apply_migration(name: str, path: str, conn: DbConnection, already_applied: Set[str]) -> None:
"""
Check if a migration is applied and if not, run it.
:param name: Migration name (key). This must be unique.
:param path: Path to migration sql file.
:param conn: Already-open database connection.
:param already_applied: A set of which migrations have already been applied. The current migration will be
added to this set if successful.
:return:
"""
if name in already_applied:
return
with open(path, "r") as f:
conn.execute(f.read(), multi=True)
already_applied.add(name)
conn.execute("INSERT INTO migrations (migration_key, migration_time) VALUES (%s, UTC_TIMESTAMP())",
(name,))
if __name__ == "__main__":
run()
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.