30 lines
997 B
Python
30 lines
997 B
Python
|
|
import datetime
|
||
|
|
import os
|
||
|
|
|
||
|
|
|
||
|
|
def is_snake_case(s):
|
||
|
|
if not s:
|
||
|
|
return False
|
||
|
|
|
||
|
|
return s.islower() and all(char.isalpha() or char == '_' for char in s)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
migration_name = ""
|
||
|
|
while not is_snake_case(migration_name):
|
||
|
|
if migration_name:
|
||
|
|
print(f"{migration_name} ist nicht im Camcel-Case")
|
||
|
|
migration_name = input('Gebe einen Namen für die Migration im snake_case an: ')
|
||
|
|
|
||
|
|
timestamp = datetime.datetime.now().timestamp()
|
||
|
|
migrations_path = os.path.join(os.path.dirname(__file__), 'migrations')
|
||
|
|
print(migrations_path)
|
||
|
|
|
||
|
|
try:
|
||
|
|
if not os.path.isdir(migrations_path):
|
||
|
|
raise FileNotFoundError
|
||
|
|
|
||
|
|
file = open(os.path.join(os.path.dirname(__file__), 'migrations', str(int(timestamp)) + '_' + migration_name + '.sql'), 'w')
|
||
|
|
file.close()
|
||
|
|
|
||
|
|
except FileNotFoundError:
|
||
|
|
print("migrations/ Directive could not be found within the db directory, contained in the project main directory.")
|