Auto Migration generation for Vapor projects

Overview

AutoMigrator

A package that generates version based migrations from Fluent.Model types.

The project will check your database scheme and understand when you have added, changed or deleted a table.

.package(url: "https://github.com/MatsMoll/AutoMigrator", from: "0.1.0")

All that is required is to add a new target in your product, with a main.swift file and add the following code

@testable import YourApp
import Vapor
import AutoMigrator

var env = try Environment.detect()
let app = Application(env)

// Setup your database connection
try configure(app)

try AutoMigrator(app: app).generateMigrations(
    tables: [
        generateTable(SomeModel.self),
        generateTable(SomeOtherModel.self),
        ...
    ],
    outputDir: app.directory.workingDirectory
)

Example output could be something like:

extension MigrationBatch2.User: AsyncMigration {
    func prepare(on database: Database) async throws {
        try await database.schema("User")
            .field("email", .string, .required)
            .field("siwaID", .string)
            .update()
    }

    func revert(on database: Database) async throws {
        try await database.schema("User")
            .deleteField("email")
            .deleteField("siwaID")
            .update()
    }
}

extension MigrationBatch2.OtherModel: AsyncMigration {
    func prepare(on database: Database) async throws {
        try await database.schema("WorkoutSummary")
            .field("workoutID", .uuid, .references("Workout", .id, onDelete: .cascade, onUpdate: .cascade))
            .field("id", .uuid, .identifier(auto: false))
            .field("averagePower", .int64)
            .field("normalizedPower", .int64)
            .field("maxPower", .int64)
            .field("averageHeartRate", .int64)
            .field("averageHeartRate", .int64)
            .field("startedAt", .datetime, .required)
            .create()
    }

    func revert(on database: Database) async throws {
        try await database.schema("WorkoutSummary")
            .delete()
    }
}
You might also like...
Next generation iOS and Android apps for Mattermost in React Native

Mattermost Mobile Minimum Server versions: Current ESR version (5.37.0) Supported iOS versions: 11+ Supported Android versions: 7.0+ Mattermost is an

Next generation debugging framework for iOS
Next generation debugging framework for iOS

Alpha is the idea of a next generation debugging framework for iOS applications. It combines multiple debugging tools built on top of a simple, unifie

iOS localization swift code generation project

code-gen-library - localization-swift module code-gen-library - localization-swift module with Python bash script execute to localization swift files(

Random and time-ordered UUID generation in Swift

UniqueID UUIDv4 and v6* generation in Swift. [API Reference] A UUID is an identifier that is unique across both space and time, with respect to the sp

Next-generation file browser for iOS.
Next-generation file browser for iOS.

Files Next-generation file browser for iOS. Multiple-column-UI on iPad System-wide Document Provider - open files in other apps Go to Folder Sorting o

A repository to experiment around the use and generation of tokens for the JLL/T Design System

Basic Style Dictionary This example code is bare-bones to show you what this framework can do. If you have the style-dictionary module installed globa

Core Data Generator (CDG for short) is a framework for generation (using Sourcery) of Core Data entities from plain structs/classes/enums.
Core Data Generator (CDG for short) is a framework for generation (using Sourcery) of Core Data entities from plain structs/classes/enums.

Core Data Generator Introduction Features Supported platforms Installation CDG Setup RepositoryType ModelType DataStoreVersion MigrationPolicy Basic U

RSA public/private key generation, RSA, AES encryption/decryption, RSA sign/verify in Swift with CommonCrypto in iOS and OS X

SwCrypt Create public and private RSA keys in DER format let (privateKey, publicKey) = try! CC.RSA.generateKeyPair(2048) Convert them to PEM format l

Util for generation RSA keys on your client and save to keychain or convert into Data 🔑 🔐

RSASwiftGenerator 🔑 🔐 To run the example project, clone the repo, and run pod install from the Example directory first. Requirements ⚠️ SWIFT 4 XCod

XCode and Swift game based on the generation of random cards and some functions related to the comparison of the results.
XCode and Swift game based on the generation of random cards and some functions related to the comparison of the results.

war-card-game-V1 XCode and Swift game based on the generation of random cards and some functions related to the comparison of the results. Once a card

Delightful code generation for OpenAPI specs for Swift written in Swift
Delightful code generation for OpenAPI specs for Swift written in Swift

Create API Delightful code generation for OpenAPI specs for Swift written in Swi

A macOS app for code generation, automation
A macOS app for code generation, automation

A macOS app for code generation, automation

compiler-driven, structured, type-safe source generation. never use gyb again!

factory 2022-09-10-a factory is a structured, type-safe source generation tool. It is intended to be a replacement for (and improvement over) the gyb

🗃 Powerful and easy to use Swift Query Builder for Vapor 3.
🗃 Powerful and easy to use Swift Query Builder for Vapor 3.

⚠️ This lib is DEPRECATED ⚠️ please use SwifQL with Bridges Quick Intro struct PublicUser: Codable { var name: String var petName: String

A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.

Puffery An iOS App written in SwiftUI to send push notifications fueled by Siri Shortcuts. You can follow other's channels and directly receive update

Simple Application that registers Vapor Leaf's .leaf file type to LaunchServices as html enabling automatic syntax highlighting in Xcode.
Simple Application that registers Vapor Leaf's .leaf file type to LaunchServices as html enabling automatic syntax highlighting in Xcode.

Vapor Leaf Extension Update: The Vapor Leaf Extension is now meant to be used with the Xcode Plugin I designed to provide Xcode language support for t

Swift Bot with Vapor for Telegram Bot Api

Telegram Vapor Bot Please support Swift Telegram Vapor Bot Lib development by giving a ⭐️ Telegram Bot based on Swift Vapor. Swift Server Side Communi

A template Vapor app with nginx frontend.
A template Vapor app with nginx frontend.

This is an example Vapor app. It contains the app itself, as well as surrounding components (Postgres database, nginx frontend for providing secure connection), all runnable out of the box with docker compose. It is a good starting point for Vapor development of an API server which you could access from macOS and iOS clients.

VaporDocC provides middleware for use with Vapor.

VaporDocC provides middleware for use with Vapor. To initialise the middleware pass in the path to your .doccarchive, e.g.:

Owner
Mats Eikeland Mollestad
Computer Science Engineering student @ NTNU
Mats Eikeland Mollestad
A dockerized microservice written in Swift using Vapor.

price-calculation-service-swift This is an example project for a university project. It uses Vapor to serve a microservice written in Swift. The point

Fabian Geistert 1 Aug 23, 2022
A template to get vapor working on Google App Engine

Swift Vapor App Engine This is a template to get vapor working on Google App Engine. Really all that's special is that it has a Dockerfile (included w

Michael 2 Oct 10, 2022
Test project to reproduce a lockup in Vapor

Test project to reproduce a lockup in Vapor The issue was first observed when backing up the SPI database during operation. Running pg_dump would caus

Sven A. Schmidt 1 Dec 30, 2021
Vapor-telemetrydeck - Vapor client for posting signals to TelemetryDeck, a privacy-conscious analytics service for apps and websites

Vapor-telemetrydeck - Vapor client for posting signals to TelemetryDeck, a privacy-conscious analytics service for apps and websites

Sidetrack 7 Jun 16, 2022
OpenAPI specification generator for Vapor based Swift projects.

VaporToOpenAPI VaporToOpenAPI is a Swift library which can generate output compatible with OpenAPI version 3.0.1 from Vapor code. You can use generate

null 3 Dec 15, 2022
Next Generation of ShadowsocksX

ShadowsocksX-NG Download Next Generation of ShadowsocksX Why a new implementation? It's hard to maintain the original implementation as there is too m

shadowsocks 30.9k Jan 4, 2023
A tool for Swift code modification intermediating between code generation and formatting.

swift-mod A tool for Swift code modification intermediating between code generation and formatting. Overview swift-mod is a tool for Swift code modifi

Ryo Aoyama 95 Nov 3, 2022
RandomKit is a Swift framework that makes random data generation simple and easy.

RandomKit is a Swift framework that makes random data generation simple and easy. Build Status Installation Compatibility Swift Package Manager CocoaP

Nikolai Vazquez 1.5k Dec 29, 2022
Aesthetic color-scheme generation written in Swift

Lorikeet Lightweight framework for generating visually aesthetic color-schemes in Swift Requirements UIKit Features What can Lorikeet do for you Calcu

Þorvaldur Rúnarsson 31 Jun 21, 2022
Core Data code generation

mogenerator Visit the project's pretty homepage. Here's mogenerator's elevator pitch: mogenerator is a command-line tool that, given an .xcdatamodel f

Wolf Rentzsch 3k Dec 30, 2022