
import json
from api import config

CURRENT_DATABASE_VERSION = 1 # An int that is bumped when a new 

def confirm_schema_match():
	"""
	Checks version of database schema

	Returns (0)  if DB schema version matches requirements.
	Returns (42) if DB schema version does not match
	             requirements and can be upgraded.
	Returns (43) if DB schema version does not match
	             requirements and cannot be upgraded,
	             perhaps because code is at lower version
	             than the DB schema version.
	"""

	version = config.db.version.find_one({"_id": "version"})
	if version is None or version.get('database', None) is None:
		return 42 # At version 0

	db_version = version.get('database', 0)
	if not isinstance(db_version, int) or db_version > CURRENT_DATABASE_VERSION:
		return 43 
	elif db_version < CURRENT_DATABASE_VERSION:
		return 42
	else:
		return 0

def upgrade_schema():
	"""
	Upgrades db to the current schema version
    
    Returns (0) if upgrade is successful
    """

	# In progress
	# db_version = version.get('database',0)
	
	# if db_version < 1:
	# 	# rename the metadata fields
	# 	config.db.container.update_many({}, {"$rename": {"metadata": "info"}})

	# config.db.version.update_one({"_id": "version"}, {"$set": {"database": CURRENT_DATABASE_VERSION}})
	return 0


import json
from api import config

CURRENT_DATABASE_VERSION = 1 # An int that is bumped when a new schema change is made

def confirm_schema_match():
    """
    Checks version of database schema

    Returns (0)  if DB schema version matches requirements.
    Returns (42) if DB schema version does not match
                 requirements and can be upgraded.
    Returns (43) if DB schema version does not match
                 requirements and cannot be upgraded,
                 perhaps because code is at lower version
                 than the DB schema version.
    """

    version = config.db.version.find_one({"_id": "version"})
    if version is None or version.get('database', None) is None:
        return 42 # At version 0

    db_version = version.get('database', 0)
    if not isinstance(db_version, int) or db_version > CURRENT_DATABASE_VERSION:
        return 43 
    elif db_version < CURRENT_DATABASE_VERSION:
        return 42
    else:
        return 0

def upgrade_schema():
    """
    Upgrades db to the current schema version
    
    Returns (0) if upgrade is successful
    """

    # In progress
    # db_version = version.get('database',0)
    
    # if db_version < 1:
    #   # rename the metadata fields
    #   config.db.container.update_many({}, {"$rename": {"metadata": "info"}})

    # config.db.version.update_one({"_id": "version"}, {"$set": {"database": CURRENT_DATABASE_VERSION}})
    return 0

Fix tab vs spaces issue
Fix tab vs spaces issue

  
  import json
  from api import config
  
- CURRENT_DATABASE_VERSION = 1 # An int that is bumped when a new 
+ CURRENT_DATABASE_VERSION = 1 # An int that is bumped when a new schema change is made
  
  def confirm_schema_match():
- 	"""
+     """
- 	Checks version of database schema
+     Checks version of database schema
  
- 	Returns (0)  if DB schema version matches requirements.
+     Returns (0)  if DB schema version matches requirements.
- 	Returns (42) if DB schema version does not match
+     Returns (42) if DB schema version does not match
- 	             requirements and can be upgraded.
+                  requirements and can be upgraded.
- 	Returns (43) if DB schema version does not match
+     Returns (43) if DB schema version does not match
- 	             requirements and cannot be upgraded,
+                  requirements and cannot be upgraded,
- 	             perhaps because code is at lower version
+                  perhaps because code is at lower version
- 	             than the DB schema version.
+                  than the DB schema version.
- 	"""
+     """
  
- 	version = config.db.version.find_one({"_id": "version"})
+     version = config.db.version.find_one({"_id": "version"})
- 	if version is None or version.get('database', None) is None:
+     if version is None or version.get('database', None) is None:
- 		return 42 # At version 0
+         return 42 # At version 0
  
- 	db_version = version.get('database', 0)
+     db_version = version.get('database', 0)
- 	if not isinstance(db_version, int) or db_version > CURRENT_DATABASE_VERSION:
+     if not isinstance(db_version, int) or db_version > CURRENT_DATABASE_VERSION:
- 		return 43 
+         return 43 
- 	elif db_version < CURRENT_DATABASE_VERSION:
+     elif db_version < CURRENT_DATABASE_VERSION:
- 		return 42
- 	else:
- 		return 0
+         return 42
+     else:
+         return 0
  
  def upgrade_schema():
- 	"""
+     """
- 	Upgrades db to the current schema version
+     Upgrades db to the current schema version
      
      Returns (0) if upgrade is successful
      """
  
- 	# In progress
+     # In progress
- 	# db_version = version.get('database',0)
+     # db_version = version.get('database',0)
- 	
+     
- 	# if db_version < 1:
+     # if db_version < 1:
- 	# 	# rename the metadata fields
+     #   # rename the metadata fields
- 	# 	config.db.container.update_many({}, {"$rename": {"metadata": "info"}})
+     #   config.db.container.update_many({}, {"$rename": {"metadata": "info"}})
  
- 	# config.db.version.update_one({"_id": "version"}, {"$set": {"database": CURRENT_DATABASE_VERSION}})
+     # config.db.version.update_one({"_id": "version"}, {"$set": {"database": CURRENT_DATABASE_VERSION}})
- 	return 0
+     return 0
  
Fix tab vs spaces issue
## Code Before:

import json
from api import config

CURRENT_DATABASE_VERSION = 1 # An int that is bumped when a new 

def confirm_schema_match():
	"""
	Checks version of database schema

	Returns (0)  if DB schema version matches requirements.
	Returns (42) if DB schema version does not match
	             requirements and can be upgraded.
	Returns (43) if DB schema version does not match
	             requirements and cannot be upgraded,
	             perhaps because code is at lower version
	             than the DB schema version.
	"""

	version = config.db.version.find_one({"_id": "version"})
	if version is None or version.get('database', None) is None:
		return 42 # At version 0

	db_version = version.get('database', 0)
	if not isinstance(db_version, int) or db_version > CURRENT_DATABASE_VERSION:
		return 43 
	elif db_version < CURRENT_DATABASE_VERSION:
		return 42
	else:
		return 0

def upgrade_schema():
	"""
	Upgrades db to the current schema version
    
    Returns (0) if upgrade is successful
    """

	# In progress
	# db_version = version.get('database',0)
	
	# if db_version < 1:
	# 	# rename the metadata fields
	# 	config.db.container.update_many({}, {"$rename": {"metadata": "info"}})

	# config.db.version.update_one({"_id": "version"}, {"$set": {"database": CURRENT_DATABASE_VERSION}})
	return 0

## Instruction:
Fix tab vs spaces issue
## Code After:

import json
from api import config

CURRENT_DATABASE_VERSION = 1 # An int that is bumped when a new schema change is made

def confirm_schema_match():
    """
    Checks version of database schema

    Returns (0)  if DB schema version matches requirements.
    Returns (42) if DB schema version does not match
                 requirements and can be upgraded.
    Returns (43) if DB schema version does not match
                 requirements and cannot be upgraded,
                 perhaps because code is at lower version
                 than the DB schema version.
    """

    version = config.db.version.find_one({"_id": "version"})
    if version is None or version.get('database', None) is None:
        return 42 # At version 0

    db_version = version.get('database', 0)
    if not isinstance(db_version, int) or db_version > CURRENT_DATABASE_VERSION:
        return 43 
    elif db_version < CURRENT_DATABASE_VERSION:
        return 42
    else:
        return 0

def upgrade_schema():
    """
    Upgrades db to the current schema version
    
    Returns (0) if upgrade is successful
    """

    # In progress
    # db_version = version.get('database',0)
    
    # if db_version < 1:
    #   # rename the metadata fields
    #   config.db.container.update_many({}, {"$rename": {"metadata": "info"}})

    # config.db.version.update_one({"_id": "version"}, {"$set": {"database": CURRENT_DATABASE_VERSION}})
    return 0
