[fix] added auth migration

This commit is contained in:
Saurabh
2017-03-15 18:46:54 +05:30
parent 2726edbb7c
commit 87c2290c7e

View File

@@ -2,69 +2,80 @@ import frappe
from frappe.database import Database
from markdown2 import markdown
from frappe.utils import validate_email_add
def migrate():
frappe.flags.mute_emails = True
source = Database(user='095452c6b4', password='FLpERmWJGuh4N3Eb')
source = Database(user='5a0a48926f6a52c6', password='ihUTM3eN3JgVoyGp')
# users = source.sql('select * from tabUser', as_dict=1)
# for u in users:
# frappe.get_doc(dict(
# doctype='User',
# name=u.name,
# first_name=u.first_name,
# last_name=u.last_name,
# email=u.email
# )).insert(ignore_if_duplicate=True)
# print u.name
users = source.sql('select * from tabUser', as_dict=1)
for u in users:
if validate_email_add(u.email.strip()):
frappe.get_doc(dict(
doctype='User',
name=u.name,
first_name=u.first_name,
last_name=u.last_name,
email=u.email
)).insert(ignore_if_duplicate=True)
print u.name
# frappe.db.sql('delete from `tabService Provider`')
# partners = source.sql('select * from `tabFrappe Partner`', as_dict=True)
# for p in partners:
# d = frappe.get_doc(dict(
# doctype='Service Provider',
# title=p.partner_name,
# country=p.country,
# image=p.logo,
# introduction=p.introduction,
# details=markdown(p.description),
# address=p.partner_address,
# discuss_ids=p.community_members,
# website=p.partner_website,
# github_id=p.github_id,
# owner=p.owner,
# creation=p.creation,
# email= p.email,
# phone=p.phone,
# route=p.route,
# show_in_website=p.show_in_website
# )).insert(ignore_if_duplicate=True, ignore_mandatory=True)
# print d.name
print "sync auth"
auth = source.sql('select * from __Auth where name != "Administrator"', as_dict=1)
for user in auth:
frappe.db.sql("""insert into __Auth
(doctype, name, fieldname, password, salt, encrypted)
values (%s, %s, %s, %s, %s, %s)""",
(user.doctype, user.name, user.fieldname, user.password, user.salt, user.encrypted), debug=1)
print user.name
# jobs = source.sql('select * from `tabFrappe Job`', as_dict=True)
# frappe.db.sql('delete from `tabPortal Job`')
# for j in jobs:
# if not frappe.db.exists('Country', j.country):
# frappe.get_doc(dict(doctype='Country', country_name=j.country)).insert()
# d = frappe.get_doc(dict(
# doctype='Portal Job',
# title=j.job_title,
# company_name=j.company_name,
# country=j.country,
# status='Open' if j.status=='Assigned' else j.status,
# job_type={
# 'ERP Implementation': 'Implementation',
# 'Core Development': 'Feature Development',
# 'Website Development': 'Website Development',
# 'Other': 'App Development'
# }.get(j.job_type, None) or j.job_type,
# description= markdown(j.job_detail),
# owner=j.owner,
# creation=j.creation,
# route=j.route,
# show_in_website=j.show_in_website
# )).insert(ignore_if_duplicate=True, ignore_mandatory=True)
# print d.name
frappe.db.sql('delete from `tabService Provider`')
partners = source.sql('select * from `tabFrappe Partner`', as_dict=True)
for p in partners:
d = frappe.get_doc(dict(
doctype='Service Provider',
title=p.partner_name,
country=p.country,
image=p.logo,
introduction=p.introduction,
details=markdown(p.description),
address=p.partner_address,
discuss_ids=p.community_members,
website=p.partner_website,
github_id=p.github_id,
owner=p.owner,
creation=p.creation,
email= p.email,
phone=p.phone,
route=p.route,
show_in_website=p.show_in_website
)).insert(ignore_if_duplicate=True, ignore_mandatory=True)
print d.name
jobs = source.sql('select * from `tabFrappe Job`', as_dict=True)
frappe.db.sql('delete from `tabPortal Job`')
for j in jobs:
if not frappe.db.exists('Country', j.country):
frappe.get_doc(dict(doctype='Country', country_name=j.country)).insert()
d = frappe.get_doc(dict(
doctype='Portal Job',
title=j.job_title,
company_name=j.company_name,
country=j.country,
status='Open' if j.status=='Assigned' else j.status,
job_type={
'ERP Implementation': 'Implementation',
'Core Development': 'Feature Development',
'Website Development': 'Website Development',
'Other': 'App Development'
}.get(j.job_type, None) or j.job_type,
description= markdown(j.job_detail),
owner=j.owner,
creation=j.creation,
route=j.route,
show_in_website=j.show_in_website
)).insert(ignore_if_duplicate=True, ignore_mandatory=True)
print d.name
apps = source.sql('select * from `tabFrappe App`', as_dict=True)
frappe.db.sql('delete from `tabFrappe App`')