You'd just use the cache api same as caching anything else
You'd just use the cache api same as caching anything else
not authorized [code: 7500] on executing sql scriptswrangler pages dev —d1 DB=IDnpx wrangler d1 execute myD1DatabaseName --local --file="./src/lib/server/d1/migrations/stocks.sql"myD1DatabaseName is the database_name in wrangler.tomlwrangler pages dev —d1 DB=1476805e-7b64-4922-90c5-003d06f3bd36npx wrangler d1 execute app --local --file="./db/my_file.sql"-- Disable foreign key enforcement
PRAGMA foreign_keys = OFF;
-- Create a temporary table to hold the existing data
CREATE TEMPORARY TABLE temp_stocks AS SELECT * FROM stocks;
-- Drop the existing stocks table
DROP TABLE stocks;
-- Create a new stocks table with the additional uniqueStockId column
CREATE TABLE stocks (
id INTEGER PRIMARY KEY,
conversionFactor REAL NOT NULL,
createdBy INTEGER NOT NULL,
createdAt REAL NOT NULL,
updatedBy INTEGER,
updatedAt REAL,
branch INTEGER NOT NULL,
product INTEGER NOT NULL,
stock INTEGER NOT NULL,
uniqueStockId TEXT UNIQUE, -- New column with UNIQUE constraint
FOREIGN KEY (branch) REFERENCES branches (id),
FOREIGN KEY (product) REFERENCES products (id),
FOREIGN KEY (createdBy) REFERENCES users (id),
FOREIGN KEY (updatedBy) REFERENCES users (id)
);
-- Populate the new stocks table with data from the temporary table, computing the uniqueStockId
INSERT INTO stocks (id, conversionFactor, createdBy, createdAt, updatedBy, updatedAt, branch, product, stock, uniqueStockId)
SELECT id, conversionFactor, createdBy, createdAt, updatedBy, updatedAt, branch, product, stock, CAST(branch || '-' || product AS TEXT) AS uniqueStockId
FROM temp_stocks;
PRAGMA foreign_keys = ON;# Create Table
bun wrangler d1 execute -j --local --command "CREATE TABLE demo2 ( id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(20), hint TEXT ); INSERT INTO demo2 (name, hint) VALUES ('hey', 'hi')" app
# Run Pages
bun wrangler pages dev . --d1 DB=1476805e-7b64-4922-90c5-003d06f3bd36