Add all repos
This commit is contained in:
parent
faa12c60bc
commit
8a91c9b89b
369 changed files with 29047 additions and 28 deletions
46
zammad-addon-metamigo/new-migration.py
Executable file
46
zammad-addon-metamigo/new-migration.py
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python3
|
||||
import pathlib
|
||||
import os
|
||||
import json
|
||||
import glob
|
||||
import inflection
|
||||
from datetime import datetime
|
||||
from collections import OrderedDict
|
||||
|
||||
migration_template = """class {} < ActiveRecord::Migration[5.2]
|
||||
def self.up
|
||||
# add your code here
|
||||
end
|
||||
|
||||
def self.down
|
||||
# add your code here
|
||||
end
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
def load_skeleton():
|
||||
t = glob.glob('*.szpm.template')
|
||||
if len(t) != 1:
|
||||
raise Exception("Cannot find szpm template")
|
||||
with open(t[0], 'r', encoding='utf-8') as f:
|
||||
skeleton = json.load(f, object_pairs_hook=OrderedDict)
|
||||
return skeleton
|
||||
|
||||
|
||||
def main():
|
||||
skeleton = load_skeleton()
|
||||
name = skeleton["name"].lower()
|
||||
raw_name = input("Enter migration name (no spaces, no symbols!): ")
|
||||
migration_base_name = "{}_{}".format(name, inflection.underscore(raw_name))
|
||||
migration_name = inflection.camelize(migration_base_name, uppercase_first_letter=True)
|
||||
contents = migration_template.format(migration_name)
|
||||
time = datetime.utcnow().strftime("%Y%m%d%H%M%S")
|
||||
migration_file_name = "{}_{}.rb".format(time, migration_base_name)
|
||||
dir_path = os.path.join("src/db/addon", name)
|
||||
pathlib.Path(dir_path).mkdir(parents=True, exist_ok=True)
|
||||
with open(os.path.join(dir_path, migration_file_name), 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue