CREATE TABLE daily_metrics (
id BIGGENERATED ALWAYS AS IDENTITY PRIMARY KEY,
tenant_id BIGINT NOT NULL,
metric TEXT NOT NULL,
day DATE NOT NULL,
count BIGINT NOT NULL DEFAULT 0,
from django.db import migrations
def populate_slugs(apps, schema_editor):
"""Generate slugs for existing posts."""
Post = apps.get_model('blog', 'Post')
<?php
use App\Http\Controllers\DocumentsController;
use Illuminate\Support\Facades\Route;
Route::middleware('auth')->group(function () {
class CreateIdempotencyKeys < ActiveRecord::Migration[7.1]
def change
create_table :idempotency_keys do |t|
t.string :key, null: false
t.string :request_path, null: false
t.datetime :locked_at
class CreateAuditLogs < ActiveRecord::Migration[7.1]
def change
create_table :audit_logs do |t|
t.references :auditable, polymorphic: true, null: false
t.references :user, null: true, foreign_key: true
t.string :action, null: false
from django.db import models
from django.utils.text import slugify
class Article(models.Model):
title = models.CharField(max_length=200)
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
from django.db import models
from django.utils import timezone
class WebhookEvent(models.Model):
class Status(models.TextChoices):
class CreateCustomerRevenueSummaries < ActiveRecord::Migration[7.0]
def change
create_view :customer_revenue_summaries, materialized: true, version: 1
add_index :customer_revenue_summaries,
:customer_id,
CREATE TABLE subscriptions (
id BIGGENERATED ALWAYS AS IDENTITY PRIMARY KEY,
customer_id BIGINT NOT NULL,
plan_code TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'active',
current_period_end TIMESTAMPTZ NOT NULL,
-- Step 1: add the column nullable, no default.
-- Catalog-only change in Postgres 11+, returns instantly.
ALTER TABLE orders
ADD COLUMN currency text;
-- Optional: keep the lock attempt bounded so a long-running
from django.db import models
from django.utils import timezone
class SoftDeleteQuerySet(models.QuerySet):
def delete(self):