teodevgroup / teo

Schema-driven web server framework.
https://teodev.io
Apache License 2.0
1.33k stars 43 forks source link

Panic during SQLite migration with Teo due to reserved index name conflict #70

Closed v423 closed 1 week ago

v423 commented 2 weeks ago

I have created a join table UserAndPrescription connecting User and Prescription, but each time the project starts, this error occurs. Being less familiar with database concepts, I am unsure how to address this issue properly. Here are the details of the Teo framework version I am using:

enviroment: nodejs: 22.0.0 @teocloud/teo: 0.2.36

error

sqlite connector connected for `main` at "sqlite:medicine.sqlite"
thread 'tokio-runtime-worker' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/teo-sql-connector-0.2.32/src/migration/migrate.rs:202:73:
called `Result::unwrap()` on an `Err` value: Error { kind: QueryError(SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("object name reserved for internal use: sqlite_autoindex_UserAndPrescription_1"))), original_code: Some("1"), original_message: Some("object name reserved for internal use: sqlite_autoindex_UserAndPrescription_1") }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

code

connector {
  provider: .sqlite,
  url: "sqlite:medicine.sqlite"
}

server {
  bind:("0.0.0.0", 8088)
}

model User{
  @id @autoIncrement @readonly
  id: Int 
  name: String

  @relation(through:UserAndPrescription, local: .user, foreign: .prescription)
  prescriptions: Prescription[]
}

model Prescription{
  @id @autoIncrement @readonly
  id: Int 

  title: String 
  note: String? 

  start_date: Int
  end_date: Int?

  @relation(through:UserAndPrescription, local: .prescription, foreign: .user)
  users: User[] 

}

@id([.userId, .prescriptionId])
model UserAndPrescription{
  @foreignKey
  userId: Int
  @foreignKey
  prescriptionId: Int

  @relation(fields: .userId, references: .id)
  user: User
  @relation(fields: .prescriptionId, references: .id)
  prescription: Prescription
}
victorteokw commented 1 week ago

Hi @v423, this bug is fixed in the 0.3.0-alpha development version.