How to use getVersionAndFileMap method of com.testsigma.config.DatabaseMigrationConfig class

Best Testsigma code snippet using com.testsigma.config.DatabaseMigrationConfig.getVersionAndFileMap

Source:DatabaseMigrationConfig.java Github

copy

Full Screen

...65 If db is up to date, we just add migration entries if any without executing SQLs66 */67 private void addMigrationEntries() throws SQLException, IOException {68 log.debug("....Adding migration entries....");69 SortedMap<Integer, File> versionAndFileMap = getVersionAndFileMap();70 int installedRank = 1;71 for (Integer version : versionAndFileMap.keySet()) {72 File migrationFile = versionAndFileMap.get(version);73 int checksum = getChecksum(migrationFile.getAbsolutePath());74 addMigrationEntryToHistory(installedRank, version, migrationFile, checksum);75 installedRank++;76 }77 }78 private void executeBootStrap() throws SQLException {79 log.info("Executing bootstrap");80 Flyway flyway = Flyway.configure().dataSource(dataSourceUrl, dataSourceUser, dataSourcePassword)81 .locations(SCHEMA_PATH_RESOURCE)82 .placeholderReplacement(false)83 .load();84 flyway.migrate();85 clearHistoryForSchema();86 }87 private void clearHistoryForSchema() throws SQLException {88 Statement stmt = connection.createStatement();89 stmt.executeUpdate(DELETE_HISTORY);90 }91 private boolean isNewDatabase() throws SQLException {92 ResultSet resultSet = connection.createStatement().executeQuery("SHOW TABLES");93 return !(resultSet.next());94 }95 private int getChecksum(String absoluteFilePath) {96 FileSystemResource r = new FileSystemResource(null, absoluteFilePath, Charset.forName("UTF-8"), false);97 return ChecksumCalculator.calculate(r);98 }99 private SortedMap<Integer, File> getVersionAndFileMap() throws IOException {100 SortedMap<Integer, File> sortedByVersion = new TreeMap<>();//We need to sort by version for DB entry101 Set<File> migrationSQLFiles;102 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();103 URL url = classLoader.getResource(MIGRATION_PATH);104 if(url == null){105 return sortedByVersion;106 }107 String urlProtocol = url.getProtocol();108 log.debug(String.format("URL Path:%s, URL protocol:%s", url.getPath(),urlProtocol));109 if (urlProtocol.equalsIgnoreCase("jar")) {110 log.debug("URL type is jar, extracting migration files from jar");111 JarExtractorUtil jarExtractorUtil = new JarExtractorUtil();112 migrationSQLFiles = jarExtractorUtil.extractJarAndCreateTempFiles(url,MIGRATION_PATH,".sql");113 } else {...

Full Screen

Full Screen

getVersionAndFileMap

Using AI Code Generation

copy

Full Screen

1public static Map<String, String> getVersionAndFileMap(String path) {2 Map<String, String> versionAndFileMap = new HashMap<>();3 try {4 File folder = new File(path);5 File[] listOfFiles = folder.listFiles();6 for (File file : listOfFiles) {7 if (file.isFile()) {8 String fileName = file.getName();9 String[] fileNameSplit = fileName.split("_");10 String version = fileNameSplit[0];11 String filePath = file.getAbsolutePath();12 versionAndFileMap.put(version, filePath);13 }14 }15 } catch (Exception e) {16 e.printStackTrace();17 }18 return versionAndFileMap;19}20public static String getLatestVersion(String path) {21 Map<String, String> versionAndFileMap = getVersionAndFileMap(path);22 String latestVersion = null;23 String latestVersionNumber = null;24 for (String version : versionAndFileMap.keySet()) {25 if (latestVersionNumber == null) {26 latestVersionNumber = version;27 latestVersion = versionAndFileMap.get(version);28 } else {29 if (version.compareTo(latestVersionNumber) > 0) {30 latestVersionNumber = version;31 latestVersion = versionAndFileMap.get(version);32 }33 }34 }35 return latestVersion;36}37public static File getLatestVersionFile(String path) {38 String latestVersion = getLatestVersion(path);39 File file = new File(latestVersion);40 return file;41}42public static String getLatestVersionFilePath(String path) {43 File file = getLatestVersionFile(path);44 String filePath = file.getAbsolutePath();45 return filePath;46}47public static String getLatestVersionFileName(String path) {48 File file = getLatestVersionFile(path);49 String fileName = file.getName();50 return fileName;51}52public static String getLatestVersionFileNameWithoutExtension(String path) {53 String fileName = getLatestVersionFileName(path);54 String[] fileNameSplit = fileName.split("\\.");

Full Screen

Full Screen

getVersionAndFileMap

Using AI Code Generation

copy

Full Screen

1def versionAndFileMap = com.testsigma.config.DatabaseMigrationConfig.getVersionAndFileMap()2def version = versionAndFileMap.get('version')3def file = versionAndFileMap.get('file')4def sqlFile = new File(file)5def databaseConnection = com.testsigma.config.DatabaseMigrationConfig.getDatabaseConnection()6def result = com.testsigma.config.DatabaseMigrationConfig.executeSql(sql, databaseConnection)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful