Skip to content

Commit 86914a9

Browse files
committed
Create directories on migrate or query
1 parent c7e9f44 commit 86914a9

6 files changed

Lines changed: 10 additions & 25 deletions

File tree

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ Once the project has been added it is time to setup the queries and migrations f
146146
otter init
147147
```
148148

149-
This will create all diretories needed and will create your first migration. Your project should have 2 new folders and a swift file. In the migrations folder you will have a file named `1.sql`. You put your first migration code in there.
150-
```
151-
/Migrations/1.sql
152-
/Queries
153-
```
149+
This will create an `otter.yaml` configuration file. Here is where you can setup the project and define the directories of the migrations and queries and other project settings.
154150

155151
> [!TIP]
156152
> Follow the SQL standard and use singular table names. This will stop table structs from being named plural
@@ -166,7 +162,7 @@ This will compile and check all migrations and queries, then generate all Swift
166162
### Adding a New Migration
167163
When a new migration is needed, you can simply add a new file with a number 1 higher than the previous. To automatically do this the cli tool can do it for you by running
168164
```
169-
otter migrate add
165+
otter migrations add
170166
```
171167

172168
# Opening a Connection

Sources/Compiler/Project.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ public struct Project {
4747
fileSystem.exists(at: queriesDirectory)
4848
}
4949

50-
public func setup() throws {
51-
try fileSystem.create(directory: migrationsDirectory)
52-
try fileSystem.create(directory: queriesDirectory)
53-
}
54-
5550
public func doesQueryExist(withName name: String) -> Bool {
5651
let fileUrl = queriesDirectory.appendingPathComponent("\(name).sql")
5752
return fileSystem.exists(at: fileUrl)
@@ -62,6 +57,8 @@ public struct Project {
6257
fatalError("Failed to get blank string data")
6358
}
6459

60+
try fileSystem.create(directory: queriesDirectory)
61+
6562
let fileUrl = queriesDirectory.appendingPathComponent("\(name).sql")
6663

6764
fileSystem.write(data, to: fileUrl)
@@ -72,6 +69,8 @@ public struct Project {
7269
fatalError("Failed to get blank string data")
7370
}
7471

72+
try fileSystem.create(directory: migrationsDirectory)
73+
7574
let nextMigration = try fileSystem.files(at: migrationsDirectory)
7675
.compactMap { $0.split(separator: ".").first }
7776
.compactMap { Int($0) }
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// MigrateCommand.swift
2+
// MigrationsCommand.swift
33
// Otter
44
//
55
// Created by Wes Wickwire on 5/21/25.
@@ -9,9 +9,9 @@ import ArgumentParser
99
import Compiler
1010
import Foundation
1111

12-
struct MigrateCommand: ParsableCommand {
12+
struct MigrationsCommand: ParsableCommand {
1313
static let configuration = CommandConfiguration(
14-
commandName: "migrate",
14+
commandName: "migrations",
1515
subcommands: [Add.self]
1616
)
1717

@@ -24,11 +24,6 @@ struct MigrateCommand: ParsableCommand {
2424
func run() throws {
2525
let config = try Config.load(at: path)
2626
let project = config.project(at: path)
27-
28-
guard project.doesMigrationsExist else {
29-
throw OtterError.sourcesNotFound
30-
}
31-
3227
try project.addMigration()
3328
}
3429
}

Sources/OtterCLI/Otter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Otter: AsyncParsableCommand {
1616
subcommands: [
1717
GenerateCommand.self,
1818
InitCommand.self,
19-
MigrateCommand.self,
19+
MigrationsCommand.self,
2020
QueriesCommand.self
2121
],
2222
defaultSubcommand: GenerateCommand.self

Sources/OtterCLI/QueriesCommand.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ struct QueriesCommand: ParsableCommand {
2727
let config = try Config.load(at: path)
2828
let project = config.project(at: path)
2929

30-
guard project.doesQueriesExist else {
31-
throw OtterError.sourcesNotFound
32-
}
33-
3430
guard !project.doesQueryExist(withName: name) else {
3531
throw OtterError.queryAlreadyExists(fileName: name)
3632
}

Tests/CompilerTests/GenTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ struct GenTests {
2323
queries: [("Queries", queries.0)],
2424
schema: compiler.schema
2525
)
26-
print(rawOutput)
2726

2827
for diagnostics in migrations.1 {
2928
Issue.record(diagnostics)

0 commit comments

Comments
 (0)