mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-05 20:16:23 +03:00
backend: добавлен скрипт для вставки начальных данных
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# TextSouls
|
||||
|
||||
|
||||
### Бэкенд
|
||||
Все действия производить из папки backend!
|
||||
|
||||
@@ -12,11 +13,18 @@ flask2postman textsouls.app --name "TextSouls" --folders > text_souls_postman.js
|
||||
```
|
||||
scripts/updatedb.sh
|
||||
```
|
||||
|
||||
###### Вставка начальных данных
|
||||
```
|
||||
python ./scripts/seed_inserter.py
|
||||
```
|
||||
|
||||
###### Запуск
|
||||
```
|
||||
scripts/runserver.sh
|
||||
```
|
||||
|
||||
|
||||
### Запуск Telegram
|
||||
Из папки Telegram:
|
||||
```
|
||||
|
||||
15
backend/scripts/init_data.json
Normal file
15
backend/scripts/init_data.json
Normal file
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"table_name": "character_classes",
|
||||
"records": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Тест1"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Тест2"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
25
backend/scripts/seed_inserter.py
Normal file
25
backend/scripts/seed_inserter.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
|
||||
import sqlalchemy
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
with open("textsouls/config.json") as config_file:
|
||||
config_data = json.load(config_file)
|
||||
|
||||
engine = sqlalchemy.create_engine(
|
||||
config_data["DB_SETTINGS"]["SQLALCHEMY_DATABASE_URI"]
|
||||
)
|
||||
metadata = sqlalchemy.MetaData(bind=engine)
|
||||
|
||||
with open("scripts/init_data.json") as seed_file:
|
||||
seed_data = json.load(seed_file)
|
||||
|
||||
for table_data in seed_data:
|
||||
table = sqlalchemy.Table(table_data["table_name"], metadata, autoload=True)
|
||||
|
||||
query = table.insert().values(table_data["records"])
|
||||
|
||||
session = Session(engine)
|
||||
session.execute(query)
|
||||
session.commit()
|
||||
session.close()
|
||||
Reference in New Issue
Block a user