├── main.py └── Index.py /main.py: -------------------------------------------------------------------------------- 1 | import org.hibernate.SessionFactory; 2 | import org.hibernate.cfg.Configuration; 3 | import liquibase.Liquibase; 4 | import liquibase.database.Database; 5 | import liquibase.database.jvm.HibernateDatabase; 6 | import liquibase.resource.ClassLoaderResourceAccessor; 7 | import java.util.logging.Logger; 8 | 9 | public class MigrationManager { 10 | private static final Logger logger = Logger.getLogger("MigrationManager"); 11 | private static SessionFactory sessionFactory; 12 | 13 | public static void main(String[] args) { 14 | try { 15 | sessionFactory = new Configuration().configure().buildSessionFactory(); 16 | runMigrations(); 17 | } catch (Exception e) { 18 | logger.severe("Database migration failed: " + e.getMessage()); 19 | throw new RuntimeException("Migration error", e); 20 | } 21 | } 22 | 23 | public static void runMigrations() { 24 | try { 25 | Database database = new HibernateDatabase(); 26 | database.setConnection(sessionFactory.getSessionFactoryOptions().getServiceRegistry() 27 | .getService(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.class) 28 | .getConnection()); 29 | 30 | Liquibase liquibase = new Liquibase("db/changelog.xml", new ClassLoaderResourceAccessor(), database); 31 | liquibase.update(""); 32 | logger.info("Database migrations applied successfully."); 33 | } catch (Exception e) { 34 | logger.severe("Migration error: " + e.getMessage()); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Index.py: -------------------------------------------------------------------------------- 1 | import random 2 | import string 3 | 4 | def generate_random_string(length=10): 5 | """Generate a random string of given length.""" 6 | return ''.join(random.choices(string.ascii_letters + string.digits, k=length)) 7 | 8 | def fibonacci(n): 9 | """Generate a Fibonacci sequence up to n.""" 10 | sequence = [0, 1] 11 | while len(sequence) < n: 12 | sequence.append(sequence[-1] + sequence[-2]) 13 | return sequence 14 | 15 | def is_prime(num): 16 | """Check if a number is prime.""" 17 | if num < 2: 18 | return False 19 | for i in range(2, int(num ** 0.5) + 1): 20 | if num % i == 0: 21 | return False 22 | return True 23 | 24 | def generate_random_numbers(count=10, lower=1, upper=100): 25 | """Generate a list of random numbers.""" 26 | return [random.randint(lower, upper) for _ in range(count)] 27 | 28 | def reverse_string(s): 29 | """Reverse a given string.""" 30 | return s[::-1] 31 | 32 | def factorial(n): 33 | """Calculate factorial of a number.""" 34 | if n == 0: 35 | return 1 36 | return n * factorial(n - 1) 37 | 38 | def main(): 39 | print("Random String:", generate_random_string(12)) 40 | print("Fibonacci Sequence:", fibonacci(10)) 41 | print("Prime Check (17):", is_prime(17)) 42 | print("Random Numbers:", generate_random_numbers()) 43 | print("Reversed String:", reverse_string("Hello World")) 44 | print("Factorial (5):", factorial(5)) 45 | 46 | if __name__ == "__main__": 47 | main() 48 | 49 | # Additional Utility Functions 50 | 51 | def count_vowels(s): 52 | """Count the number of vowels in a string.""" 53 | return sum(1 for char in s.lower() if char in "aeiou") 54 | 55 | def sort_numbers(numbers): 56 | """Sort a list of numbers in ascending order.""" 57 | return sorted(numbers) 58 | 59 | def find_max(numbers): 60 | """Find the maximum number in a list.""" 61 | return max(numbers) if numbers else None 62 | 63 | if __name__ == "__main__": 64 | sample_numbers = generate_random_numbers() 65 | print("Sorted Numbers:", sort_numbers(sample_numbers)) 66 | print("Max Number:", find_max(sample_numbers)) 67 | print("Vowel Count in 'Cryptography':", count_vowels("Cryptography")) 68 | --------------------------------------------------------------------------------